Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1994 - 1999
  6. //
  7. // File: string.hxx
  8. //
  9. //--------------------------------------------------------------------------
  10. //
  11. //
  12. // Filename: String.hxx
  13. //
  14. // Description: contains a basic string class
  15. //
  16. // Author: Scott Holden (t-scotth)
  17. //
  18. //
  19. #include <iostream.h>
  20. #include <string.h>
  21. class String
  22. {
  23. private:
  24. char *_string;
  25. unsigned int _length;
  26. public:
  27. String( ) : _string( NULL ), _length( 0 ) { }
  28. String( const char * );
  29. String( const String& );
  30. ~String( )
  31. {
  32. if ( _string ) {
  33. delete[] _string;
  34. }
  35. }
  36. char& operator[]( int );
  37. const char& operator[]( int ) const;
  38. String& operator=( const String& );
  39. String& operator=( const char * );
  40. friend ostream& operator<<( ostream&, const String& );
  41. friend istream& operator>>( istream&, String& );
  42. friend int operator==( const String &x, const char *s )
  43. { return ( strcmp( x._string, s ) == 0 ); }
  44. friend int operator==( const String &x, const String &y )
  45. { return ( strcmp( x._string, y._string ) == 0 ); }
  46. friend int operator!=( const String &x, const char *s )
  47. { return ( strcmp( x._string, s ) != 0 ); }
  48. friend int operator!=( const String &x, const String &y )
  49. { return ( strcmp( x._string, y._string ) != 0 ); }
  50. friend int operator<( const String &x, const char *s )
  51. { return ( strcmp( x._string, s ) < 0 ); }
  52. friend int operator<( const String &x, const String &y )
  53. { return ( strcmp( x._string, y._string ) < 0 ); }
  54. friend int operator>( const String &x, const char *s )
  55. { return ( strcmp( x._string, s ) > 0 ); }
  56. friend int operator>( const String &x, const String &y )
  57. { return ( strcmp( x._string, y._string ) > 0 ); }
  58. };
  59.