istream& operator>>(istream& cin, MyString& str)
{
//先清空原有内容
if (str.pString != NULL) {
delete[] str.pString;
str.pString = NULL;
}
//让用户输入的内容
char buf[1024];
cin >> buf;
//把用户输入的新内容拷备到str中
str.pString = new char[strlen(buf) + 1];
strcpy(str.pString, buf);
str.m_Size = strlen(buf);
return cin;
}
原文:https://www.cnblogs.com/lodger47/p/14696455.html