要求:
一、编写一个MyStr类,实现以下功能
1、析构函数,释放buf指向的堆空间
2、编写 append(const mystring r) 为当前字符串尾部,拼接新的字符串r
3、编写 isEqual(const mystring r) 判断当前字符串和 字符串 r是否相等
4、swap实现两个MyStr对象的内部字符串内容互换
二、运算符重载
1、+ :本质就是append str1 = "hello" str2 = "world" str3 = str1 + str2 == "helloworld"2、+= 功能
3、= 深拷贝功能
4、== 功能
5、!= 功能
6、++ 功能,字符串中所有字符的ASCII自增1
7、[]下标运算符 operator[](int index) 例如str = "hello" cout ;str[0] ;终端输出 h
8、cout 输出mystring功能
9、cin 输入mystring功能
1、MyStr.h
using namespace std;
class MyStr{
private:
char* m_buf;
int m_cap;//容量,m_buf的实际长度
public:
MyStr();
MyStr(const char* str2);
MyStr(const MyStr & str);
~MyStr();
void setB