注意事项:
1、注意为结尾符‘\0’申请一个字节的空间;
2、在拷贝构造函数和赋值函数中,注意使用深拷贝,而不是浅拷贝;
3、重载输入、输出运算符;
#include<iostream>
#include<iomanip>
using namespace std;
class CString{
friend ostream& operator<<(ostream& os, CString& str);
friend istream& operator>>(istream& is, CString& str);
private:
int iLen;
char* lpszBuff;
public:
CString(char* buff = ""){
cout << "CString构造函数" << endl;
iLen = strlen(buff);
lpszBuff = new char[iLen+1];
strcpy(lpszBuff, buff);
}
CString(const CString& other){
cout << "CString拷贝构造函数" << endl;
iLen = strlen(other.lpszBuff);
lpszBuff = new char[iLen+1];
strcpy(lpszBuff, other.lpszB