#includeusing namespace std;class String{public: String(); //默认的构造函数 ~String(){ delete []str; len=0; //cout<<"析构函数执行"< >(istream &i, String &s) { i>>s.str; return i; } //当运算符重载函数定义为成员函数时,二元运算符只带一个参数 //将这个函数定义为友元函数即可 friend bool operator<(const String&str1, const String&str2) { if(strcmp(str1.str, str2.str) < 0){ return 1; }else return 0; } friend bool operator>(const String&str1, const String&str2) { if(strcmp(str1.str, str2.str) > 0){ return 1; }else return 0; } friend bool operator==(const String&str1, const String&str2) { if(strcmp(str1.str, str2.str) == 0){ return 1; }else return 0; } //这里是可以修改的 char &operator[](unsigned short int length); char operator[](unsigned short int length)const; //复制构造函数 String (const String&r); //重载赋值运算符= String &operator=(const String &s); String operator+(const String&s); //重载相加运算符 void operator+=(const String&s); //重载相加运算符 private: String(unsigned short int); //构造带值的string unsigned short int len; char *str;};//创建一个空的str变量String::String(){ len = 0; str = new char[1]; str[0] = '\0';};String::String(const char*const ch){ //cout<<"带一个参数的构造函数"< len){ return str[len-1]; //返回可见字符的值 }else{ return str[length]; }};char String::operator[](unsigned short int length)const{ //cout<<"下标运算符const执行"< len){ return str[len-1]; //返回可见字符的值 }else{ return str[length]; }};String::String (const String&rs){ len = rs.getlen(); str = new char[len+1]; for(int i=0; i