#include <iostream>//using namespace std;//#pragma warning (disable :4996)//class string//{//public:///*string ()//:_str (New char[strlen ("") +1])//{//*_str = '//}/'; /string (const char*s)//:_str (New char[strlen (s) + 1])//{//strcpy (_str, s);//}*/// String (const char* s = "")//:_str (New char[strlen (s) + 1])//{//strcpy (_STR, s)//}//string (const string& s)//:_str (new char[(strlen (S._STR)) +1])//{//strcpy (_STR, &NBSP;S._STR);//}//string& operator= (const string& s)//{//if (this != &s)//{//delete[] _str;//need to release the original space when re-assigned, otherwise memory leaks//_str = new char[(strlen (_STR)) + 1];//strcpy (_STR,&NBSP;S._STR);//}//return *this;//}////~string ()//{//delete[] _str;//}//void display ()//{//cout << _str << endl;//}//private://char* _str;//};// Void test1 ()//{///*string s1;//s1. Display ();////string s2 (S1);//s2. Display (); */////STRING&NBSP;S1 ("ABCD");//s1. Display ();//string s2;//s2. Display ();////s2 = s1;//s2. Display ();//////}//int main ()//{//test1 ();//system ("pause");//return 0;//}
Be aware of memory management, easy memory leaks Oh!
This article is from the "Small Stop" blog, please be sure to keep this source http://10541556.blog.51cto.com/10531556/1715708
String class default constructor