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 }

 

posted @ 2020-08-05 08:30  不敢说的梦  阅读(326)  评论(0)    收藏  举报