/* ECP: FILEname=fig14_18.cpp */ /* 1*/ #include /* 2*/ #include /* 3*/ class String /* 4*/ { /* 5*/ char *Storage; // Storage for the string. /* 6*/ unsigned int StorageLen; // Amount of allocated memory. /* 7*/ inline void GetStorage( const unsigned int MaxLength ); /* 8*/ public: /* 9*/ // Constructors. /*10*/ String ( const char * Value = NULL ); /*11*/ String ( const String & Value ); /*12*/ // Destructor. /*13*/ ~String ( ) { delete [ ] Storage; } /*14*/ // Assignment operator. /*15*/ const String & operator = ( const String & Value ); /*16*/ /*17*/ // Get a single character. /*18*/ char & operator [ ] ( unsigned int Index ) const; /*19*/ // Get the length. /*20*/ unsigned int Length ( ) const { return strlen( Storage ); } /*21*/ // Friends. /*22*/ friend int operator == /*23*/ ( const String & Lhs, const String & Rhs ); /*24*/ friend int operator != /*25*/ ( const String & Lhs, const String & Rhs ); /*26*/ friend int operator < /*27*/ ( const String & Lhs, const String & Rhs ); /*28*/ friend int operator > /*29*/ ( const String & Lhs, const String & Rhs ); /*30*/ friend ostream & operator << /*31*/ ( ostream & Output, const String & Str ); /*32*/ friend istream & operator >> /*33*/ ( istream & Input, String & Str ); /*34*/ };