#include <iostream>#include <string>using namespace std;class myString{private: char* m_date;public: myString(const char* str) { if(str == NULL) { m_date = new char[1]; *m_date = '\0'; } else { int lenth = strlen(str); m_date = new char[lenth + 1]; strcpy(m_date, str); } } myString(const myString &other) { int lenth = strlen(other.m_date); m_date = new char[lenth + 1]; strcpy(m_date, other.m_date); } myString & operator = (const myString &other) { if(*this == other) return *this; delete []m_date; int lenth = strlen(other.m_date); m_date = new char[lenth + 1]; strcpy(m_date, other.m_date); return *this; } ~myString() { delete []m_date; }} 转载于:https://www.cnblogs.com/jackill/archive/2009/06/07/1498308.html