Namespace ss{class String {friend ostream& operator << (ostream&, const string&); Char *_str; Public:string (): _str (new char[1]) {_str[0] = ' + '; } string (const char* str): _str (new Char[strlen (str) +1]) {strcpy (_str, str); } string (const string & S): _str (New Char[s.size () +1]) {strcpy (_str, S._STR); } string (string&& s): _str (s._str) {s._str = nullptr; }//operator String & operator = (string s) {swap (s); return *this; } char & operator [] (int i) {return _str[i];} /* String &operator = (Const string &s) {if (this = &s) {delete []_str; if (s._str!= nullptr) {_str = new Char[strlen (S._STR) +1]; strcpy (_str, S._STR); }} return *this; }*///get size_t size () const { return strlen (_STR); }//Void swap (string& s) {Std::swap (_str, S._STR); } }; ostream& operator << (ostream& os, const string &ob) {OS << ob._str; return OS; } };
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
String Simple implementation