Professional Documents
Culture Documents
#define myString_h
#include <iostream>
#include <cstring>
using namespace std;
class MyString {
private:
char* pString;
public:
MyString();
MyString(const char* str);
MyString(const MyString& other);
~MyString();
};
#endif
#include "myString.h"
MyString::MyString() {
this->pString = nullptr;
};
MyString::~MyString() {
delete[] this->pString;
};
return *this;
};
int main() {
MyString s1;
MyString s2("Hello");
if (s2 == "Hello") {
cout << "s2 is equal to \"Hello\"" << endl;
}
else {
cout << "s2 is not equal to \"Hello\"" << endl;
}
MyString s3 = s2;
s3 += " World";
cout << "s3 after concatenation: " << s3 << endl;
s1 = s3;
cout << "s1 after assignment: " << s1 << endl;
return 0;
}