定义一个字符串类,比较运算
1 #define NULL 0 2 #include <iostream> 3 4 /* run this program using the console pauser or add your own getch, system("pause") or input loop */ 5 using namespace std; 6 class String 7 { 8 public: 9 String(){ 10 p=NULL; 11 } 12 String(char *str); 13 void display(); 14 private: 15 char *p; 16 }; 17 18 String::String(char *str) 19 { 20 p=str; 21 } 22 23 void String::display() 24 { 25 cout<<p; 26 } 27 28 int main(int argc, char** argv) { 29 String string1("Hello"),string2("Book"); 30 string1.display(); 31 cout<<endl; 32 string2.display(); 33 return 0; 34 }