#ifndef MYSTRING_H #define MYSTRING_H #include #include // For string library functions #include // For exit() function using namespace std; // The following declarations are needed by some compilers class MyString; // Forward declaration ostream &operator<<(ostream &, MyString &); istream &operator>>(istream &, MyString &); // MyString class: An abstract data type for handling strings class MyString { private: char *str; int len; public: // Default constructor. MyString() { str = 0; len = 0; } // Convert and copy constructors. MyString(char *); MyString(MyString &); // Destructor. ~MyString() { if (len != 0) delete [] str; str = 0; len = 0; } // Various member functions and operators. int length() { return len; } char *getValue() { return str; }; MyString operator+=(MyString &); MyString operator+=(const char *); MyString operator=(MyString &); MyString operator=(const char *); bool operator==(MyString &); bool operator==(const char *); bool operator!=(MyString &); bool operator!=(const char *); bool operator>(MyString &); bool operator>(const char *); bool operator<(MyString &); bool operator<(const char *); bool operator>=(MyString &); bool operator>=(const char*); bool operator<=(MyString &); bool operator<=(const char *); // Overload insertion and extraction operators. friend ostream &operator<<(ostream &, MyString &); friend istream &operator>>(istream &, MyString &); }; #endif