// A Str wraps an ordinary char array to make a C++ object. // // Each str instance owns a dynamically allocated char array that // holds the underlying \0-terminated C string. #ifndef STR_H_ #define STR_H_ #include class Str { public: // // Constructors // // create empty string Str(); // create Str from c-string s explicit Str(const char *s); // copy constructor - initialize this to be a copy of s explicit Str(const Str &s); // destructor ~Str(); // return length of this string, excluding the \0. int length() const; // return a new c-string allocated on the heap with a copy of this Str's // string data. \0-terminated. char* c_str() const; // append contents of s to the end of this string void append(const Str &s); // string assignment: replace this string with a copy of s Str& operator=(const Str &s); // stream output (global function, not class member) friend std::ostream &operator<<(std::ostream &out, const Str &s); private: char *st_; // c-string on heap with data bytes terminated by \0 }; // class Str #endif // STR_H_