1
0

string1.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // string1.h -- fixed and augmented string class definition
  2. #ifndef STRING1_H_
  3. #define STRING1_H_
  4. #include <iostream>
  5. using std::ostream;
  6. using std::istream;
  7. class String
  8. {
  9. private:
  10. char * str; // pointer to string
  11. int len; // length of string
  12. static int num_strings; // number of objects
  13. static const int CINLIM = 80; // cin input limit
  14. public:
  15. // constructors and other methods
  16. String(const char * s); // constructor
  17. String(); // default constructor
  18. String(const String &); // copy constructor
  19. ~String(); // destructor
  20. int length () const { return len; }
  21. // overloaded operator methods
  22. String & operator=(const String &);
  23. String & operator=(const char *);
  24. char & operator[](int i);
  25. const char & operator[](int i) const;
  26. // overloaded operator friends
  27. friend bool operator<(const String &st, const String &st2);
  28. friend bool operator>(const String &st1, const String &st2);
  29. friend bool operator==(const String &st, const String &st2);
  30. friend ostream & operator<<(ostream & os, const String & st);
  31. friend istream & operator>>(istream & is, String & st);
  32. // static function
  33. static int HowMany();
  34. };
  35. #endif