# Include <iostream>
Using namespace STD;
Class string
{
Public:
String (const char * STR = NULL );
String (const string & other );
~ String (void );
String & operator = (const string & other );
Const char * getstring () const;
PRIVATE:
Char * m_data;
};
String ::~ String (void)
{
Delete [] m_data;
}
String: string (const char * Str)
{
If (STR = NULL)
{
M_data = new char [1];
* M_data = '\ 0 ';
}
Else
{
Int length = strlen (STR );
M_data = new char [Length + 1];
Strcpy (m_data, STR );
}
}
String: string (const string & other)
{
Int length = strlen (other. m_data );
M_data = new char [Length + 1];
Strcpy (m_data, other. m_data );
}
String & string: Operator = (const string & other)
{
If (this = & other)
{
Return * this;
}
Delete [] m_data;
Int length = strlen (other. m_data );
M_data = new char [Length + 1];
Strcpy (m_data, other. m_data );
Return * this;
}
Const char * string: getstring () const
{
Return m_data;
}
Int main ()
{
String STR ("hello ");
String str1 ("Meng ");
String str2 (str1 );
String str3 ("Jun .");
String str4 (str3 );
String str5 = str4;
Cout <Str. getstring () <str2.getstring () <str5.getstring () <Endl;
Return 0;
}