#include //for the function strlen #include //for the function copy_n #include //for class out_of_range #include "mystring.h" using namespace std; mystring::mystring(const char *initial_p) //plain old constructor : n {strlen(initial_p) + 1}, p {new char[n]} { copy_n(initial_p, n, p); } mystring::mystring(const mystring& another) //"copy" constructor : n {another.n}, p {new char[n]} { copy_n(another.p, n, p); } mystring& mystring::operator=(const mystring& another) { if (this != &another) { delete[] p; p = new char[another.n]; copy_n(another.p, n, p); } return *this; } char mystring::operator[](size_t i) const { if (i >= n) { throw out_of_range("mystring subscript too big"); } return p[i]; } char& mystring::operator[](size_t i) { if (i >= n) { throw out_of_range("mystring subscript too big"); } return p[i]; }