// File: mystring.h // Author: Matt Small // Description: Header file for the MyString class, a custom class for storing and // manipulating strings. #include using namespace std; class MyString { friend ostream& operator<< (ostream&, const MyString&); friend istream& operator>> (istream&, MyString&); friend MyString operator+ (const MyString&, const MyString&); friend bool operator< (const MyString&, const MyString&); friend bool operator> (const MyString&, const MyString&); friend bool operator<= (const MyString&, const MyString&); friend bool operator>= (const MyString&, const MyString&); friend bool operator== (const MyString&, const MyString&); friend bool operator!= (const MyString&, const MyString&); public: MyString(); // default constructor MyString(const char*); // conversion constructor MyString(const MyString&); // copy constructor ~MyString(); // destructor const MyString& operator=(const MyString&); // assignment overload const MyString& operator+=(const MyString&); // assignment + overload char operator[] (int index) const; //const safe [] overload char& operator[](int index); //non-const [] overload char* cstring(); // returns char* pointer str int GetLength() const; // accessor for length private: void Resize(int); // resize the allocation to allow a string of // size (int param) n, meaning allocation n+1 char* str; // pointer to dynamically created char array // that stores the c-string int length; // number of readable characters in the stored string // ALLOCATED space is always to be length+1 (length plus NULL) };