代码
#include <iostream>
#include <cstring>
using namespace std;
class MyString
{
friend ostream &operator<<(ostream &out, MyString &ob);
friend istream &operator>>(istream &in, MyString &ob);
private:
char *str;
int size;
public:
MyString();
MyString(const char *str);
MyString(const MyString &ob);
~MyString();
int Size();
char& operator[] (int index);
MyString& operator= (const MyString &ob);
MyString& operator=(const char* str);
MyString& operator+ (const MyString &ob);
MyString& operator+ (const char* str);
bool operator==(const MyString &ob);
bool operator==(const char* str);
};
MyString::MyString()
{
this->str = NULL;
this->size = 0;
cout << "无参构造" << endl;
}
MyString::MyString(const char *str)
{
cout << "有参的char*构造" << endl;
this->str = new char[strlen(str) + 1];
strcpy(this->str, str);
this<