#include using namespace std; #ifndef _BSTRING_H #define _BSTRING_H class BString { friend BString operator+(const BString& s1, const BString& s2); // concat friend bool operator== (const BString& s1, const BString& s2); friend bool operator!= (const BString& s1, const BString& s2); friend bool operator< (const BString& s1, const BString& s2); friend bool operator> (const BString& s1, const BString& s2); friend bool operator<= (const BString& s1, const BString& s2); friend bool operator>= (const BString& s1, const BString& s2); friend ostream& operator<< (ostream& os, const BString& bs); friend istream& operator>> (istream& is, BString& bs); public: BString(); // default constructor, sets empty string BString(const char* c); // conversion from cstring to BString BString(const BString& bs); // copy constructor (for deep copy) BString& operator= (const BString& bs); // assignment ~BString(); // destructor -- cleanup!! BString& operator+= (const BString& bs); // concatenation int GetLength() const; // accessor private: char* str; // pointer to the dynamic array of chars int size; // tracks size of string (i.e. how many chars) // allocation will always be size+1 (for '\0') void Resize(int newsize); // increase string allocation to newsize+1 }; #endif