64,282
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
class MyString
{
friend ostream& operator<<(ostream& os, MyString ms);
private:
char *str;
public:
MyString(string s){str = new char[s.length()+1]; strcpy(str,s.c_str());};
~MyString(){delete []str;};
void prnt();
};
void MyString::prnt()
{
cout << str << endl;
}
ostream& operator<<(ostream& os, MyString ms)
{
os << ms.str << endl;
return os;
}
int main()
{
string s = "abcd xyz";
MyString s1(s);
string s2 = "hello";
cout << "s1---> " << s1 << endl;
cout << "s2---> " << s2 << endl;
getchar();
return 0;
}