tsaiwn@magpie c++% cat -n string2 .cpp 1 //string2.cpp -- @CopyLeft by tsaiwn@csie.nctu.edu.tw 2 // some useful member functions in the class string 3 #include 4 #include 5 using namespace std; 6 #include 7 int main() 8 { 9 string s("Hello here there!"); 10 string s2="Hello here there!"; 11 string t; 12 t = s + " How R U doing?"; 13 cout << "t=" << t << endl; 14 cout << "s2=" << s2 << endl; 15 cout << "s=" << s << endl; 16 cout << " (s==s2) == " << (s==s2) << endl; 17 cout << " (s> s2) == " << (s> s2) << endl; 18 cout << " (s< s2) == " << (s< s2) << endl; 19 cout << " (s> t) == " << (s> t) << endl; 20 cout << " (s< t) == " << (s< t) << endl; 21 cout << "s.substr(1,3)=" << s.substr(1,3)< s2) == 0 (s< s2) == 0 (s> t) == 0 (s< t) == 1 s.substr(1,3)=ell s.substr(6)=here there! s.length()=17 s.size()=17 after "s.insert(2,"222"); s=He222llo here there! after "s.erase(2,2); s=He2llo here there! s.find("e") = 1 s.find_last_of("e") = 16 s.find_last_of("here") = 16 s.find_first_of("here") = 1 string::npos==4294967295 s.find("E") = 4294967295 *i= H *i= e *i= 2 *i= l *i= l *i= o *i= *i= h *i= e *i= r *i= e *i= *i= t *i= h *i= e *i= r *i= e *i= ! p=He2llo here there! strlen(p)=18 strchr(p, 'e') - p ==1 cs1=ABCDEFG cs2=ABCDE strcmp(cs1, cs2) == 0 tsaiwn@magpie c++% exit exit