home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c031 / 4.ddi / SAMPLES / CPPTUTOR / STRNG.H$ / STRNG
Encoding:
Text File  |  1991-12-11  |  1007 b   |  46 lines

  1. // STRNG.H
  2.  
  3. // This is the final version of an example class from Chapter 5 of the
  4. //     C++ Tutorial. This class performs dynamic allocation of memory,
  5. //     allowing resizeable objects. It demonstrates a destructor, a
  6. //     user-defined operator=, and a copy constructor.
  7.  
  8. #if !defined( _STRNG_H_ )
  9.  
  10. #define _STRNG_H_
  11.  
  12. #include <iostream.h>
  13.  
  14. // ------- A string class
  15. class String
  16. {
  17. public:
  18.    String();
  19.    String( const char *s );
  20.    String( char c, int n );
  21.    String( const String &other );              // Copy constructor
  22.    String &operator=( const String &other );   // Assignment operator
  23.    void set( int index, char newchar );
  24.    char get( int index ) const;
  25.    int getLength() const;
  26.    void display() const;
  27.    void append( const char *addition );
  28.    ~String();
  29. private:
  30.    int length;
  31.    char *buf;
  32. };
  33.  
  34. inline int String::getLength() const
  35. {
  36.     return length;
  37. }
  38.  
  39. inline void String::display() const
  40. {
  41.     cout << buf;
  42. }
  43.  
  44. #endif  // _STRNG_H_
  45.  
  46.