【C++ 中 strcmp(a,b) 函数的用法】
● 若 len(a)>len(b),则返回1。
● 若 len(a)==len(b),则返回0。
● 若 len(a)<len(b),则返回-1。
【C++ 中 strcmp(a,b) 函数的用法代码一】
#include <bits/stdc++.h>
using namespace std;
int main() {
char s1[]="abcdefg";
char s2[]="abcdefg";
char s3[]="abcde";
printf("%d\n",strcmp(s1,s2)); //0
printf("%d\n",strcmp(s1,s3)); //1
printf("%d\n",strcmp(s3,s1)); //-1
return 0;
}
【C++ 中 strcmp(a,b) 函数的用法代码二】
#include <bits/stdc++.h>
using namespace std;
int main() {
const char* s1="abcdefg";
const char* s2="abcdefg";
const char* s3="abcde";
printf("%d\n",strcmp(s1,s2)); //0
printf("%d\n",strcmp(s1,s3)); //1
printf("%d\n",strcmp(s3,s1)); //-1
return 0;
}