strcmp函数
字符串比较函数,按字典序比较:
strcmp(s1,s2) 若s1大于s2,则返回正数,若s1小于s2,则返回负数,若相等,则返回零。
1 #include <iostream> 2 #include <cstring> // 注意头文件 3 using namespace std; 4 int main() 5 { 6 char a[] = "abcd"; 7 char b[] = "bcde"; 8 char c[] = "abcd"; 9 cout << strcmp(a,b) << endl; // 输出结果:-1 10 cout << strcmp(b,a) << endl; // 输出结果:1 11 cout << strcmp(a,c) << endl; // 输出结果:0 12 return 0; 13 }

浙公网安备 33010602011771号