//////经典string
char * strcpy(char *strdest,const char *strsrc)
{
ASSERT(strdest!=NULL&&strsrc!=NULL);
char * temp= strdest;
while((* strdest++=* strsrc++)!='\0')
NULL
return temp;
}//为了实现链式表达式
class String
{
public:
String(const char str[]);/////
String(const char ch, const int num);////
String(const char * str=NULL);
String(const string &other);
~String(void);
String & operator=(const sting & other);
char& operator[]( int ) const;//////
bool operator==( const String &str );/////
private:
char * m_data;
};
String(const char * str=NULL) ////普通的构造函数
{
if(str==NULL)
{ m_data=new char;
*m_data='\0';
}
else
{
int length=strlen(str);
m_data=new char[length];
strcpy(m_data,str);
}
}
String(const string &other) /////拷贝构造函数
{
int length=strlen(other.m_data);
m_data=new char[length+1];
strcpy(m_data,other.m_data);
}
~String(void) ////析构函数
{
delete [] m_data;
}
String & operator=(const sting & 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;
}