home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C12 / Strings1.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  672 b   |  31 lines

  1. //: C12:Strings1.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // No auto type conversion
  7. #include "../require.h"
  8. #include <cstring>
  9. #include <cstdlib>
  10. using namespace std;
  11.  
  12. class Stringc {
  13.   char* s;
  14. public:
  15.   Stringc(const char* S = "") {
  16.     s = (char*)malloc(strlen(S) + 1);
  17.     require(s != 0);
  18.     strcpy(s, S);
  19.   }
  20.   ~Stringc() { free(s); }
  21.   int strcmp(const Stringc& S) const {
  22.     return ::strcmp(s, S.s);
  23.   }
  24.   // ... etc., for every function in string.h
  25. };
  26.  
  27. int main() {
  28.   Stringc s1("hello"), s2("there");
  29.   s1.strcmp(s2);
  30. } ///:~
  31.