//File : MyString.h //Author : Andre Long //Due : October 20, 2004 //Description : This header file comes from 14.7 in book which will be used with // CH14pc4 #ifndef MYSTRING_H #define MYSTRING_H #include using namespace std; class MyString; //Forward declaration ostream &operator<<(ostream &, MyString &); istream &operator>>(istream &, MyString &); class MyString { private: char *str; int len; public: MyString() //Default constructor { str = NULL; len = 0; } MyString(MyString &right) //Copy constructor { str = new char[right.length() + 1]; strcpy(str, right.getValue()); len = right.length(); } MyString(char *sptr) //C-string constructor { len = strlen(sptr); str = new char[len + 1]; strcpy(str, sptr); } ~MyString() //Destructor { if(len != 0) delete[] str; } int length() //Returns the string length { return len; } char *getValue() //Returns the string { return str; } MyString operator+=(MyString &); char *operator+=(const char *); MyString operator=(MyString &); char *operator=(const char *); int operator==(MyString &); int operator==(const char *); int operator!=(MyString &); int 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 *); friend ostream &operator<<(ostream &, MyString &); friend istream &operator>>(istream &, MyString &); }; #endif