#include // // Please see http://www.cplusplus.com/reference/string/string/string.html // For descriptions of the functions: especially undocumented ones. :-) // // const int DEFAULT_SIZE = 64; // Returns the max of two numbers #define max(x,y) (((y) > (x)) ? (y) : (x)) class String { public: // **************** // * Constructors * // **************** /** * Create a string of DEFAULT internal length */ String(); /** * Create a String stored in an internal array of size * initCapacity. */ String(int initCapacity); /** * Create a String stored in an internal array of size * length of initString. The internal * array initially contains a copy of initString. */ String(char* initString); /** * Create a String stored in an internal array of the max size * if initCapacity and the length of initString. The internal * array initially contains a copy of initString. */ String(int initCapacity, char* initString); // ******************** // * Member Functions * // ******************** /** * Return the internal c_str array. (not a copy so this can be dangerous * since the array outside of the class can be modified. */ const char* c_str ( ) const; char& at ( int pos ); /** * The size of the string */ int size() const; /** * The size of the internal array storing the string */ int capacity() const; /** * Clear the contents of the string. */ void clear(); String& append ( const String& str ); int compare ( const String& str ) const; private: void init(int initCapacity, char* initString); // The string char *str; // The length of the string int stringLength; // The length of the internal array int arrayLength; };