//==================== //f0304.cpp //c串操作 //==================== #include<iostream> using namespace std; //-------------------- int main() { char * str = "hello"; cout << *str <<endl; //h cout << str <<endl; //hello cout << ("jion" == "jion" ? " " : " not ")<< "equal!"<<endl; //equal char * str1 = "good"; char * str2 = "good"; cout << (str1 == str2 ? " " : " not ") << "equal!" <<endl; //equal char buffer1[6] = "hello"; char buffer2[6] = "hello"; cout << (buffer1 == buffer2 ? " " : "not ") <<"equal!" <<endl;//not equal char * str3 = "hello"; char * str4 = str3; char a1[6] = "hello"; //char a2[6] = a1; //错,数组是不能复制的 char * s1 = "hello"; char * s2 = "123"; char a[20]; strcpy(a,s1); //复制 cout << (strcmp(a,s1) == 0 ? " " :"not " )<< "equal." <<endl; //比较 cout << strcat(a,s2) << endl;//连接 cout << strrev(a) <<endl; //倒置 cout <<strset(a,'c') <<endl;//设置 cout << (strstr(s1,"ell") ? " " : "not ") << "found" <<endl;//查找字符串 cout << (strchr(s2,'c') ? " " : "not ") << "found" <<endl;//查找字符 return 0; } //====================