程序崩溃!但是去掉析构函数就没有问题了,求解.......
程序代码:
#include <iostream> using namespace std; class String { public: String(){len=0;str=new char[1];str[0]='\0';} ~String(){delete []str;len=0;}; //注释掉此行就啥事没有 friend ostream &operator<<(ostream & o, const String &str){o<<str.str;return o;} friend istream &operator>>(istream&i, String &str){i>>str.str;return i;} private: unsigned short int len; char*str; }; int main() { String s1; cin >> s1; cout << s1; return 0; }