65,210
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <cstring>
using namespace std;
class Sstring
{
public:
Sstring(char *m);
~Sstring();
void display();
friend Sstring &operator -(Sstring &,Sstring &);
private:
char *str;
};
void Sstring::display()
{
cout <<str <<endl;
}
Sstring::Sstring(char* m)
{
str=new char[strlen(m)+1];
strcpy(str,m);
}
Sstring::~Sstring()
{
delete []str;
}
Sstring &operator -(Sstring &a,Sstring &b)
{
for(int m=0;b.str[m]!='\0';m++)
for(int n=0;a.str[n]!='\0';n++)
if(a.str[n]==b.str[m])
for(int i=n;a.str[i]!='\0';i++)
a.str[i]=a.str[i+1];
return a;
}
int main()
{
Sstring a("wokao"),b("ka");
a-b;
a.display();
return 0;
}