C++中字符串比较函数strcmp的用法是什么?

函数原型:

int strcmp(const char *s1, const char *s2);1

头文件:

#include <string.h>1

功能: 用来比较两个字符串

参数: s1、s2为两个进行比较的字符串

返回值: 若s1、s2字符串相等,则返回零;若s1大于s2,则返回大于零的数;否则,则返回小于零的数。

说明: strcmp()函数是根据ACSII码的值来比较两个字符串的;strcmp()函数首先将s1字符串的第一个字符值减去s2第一个字符,若差值为零则继续比较下去;若差值不为零,则返回差值。
直到出现不同的字符或遇’\0’为止。

特别注意: strcmp(const char *s1,const char * s2)这里面只能比较字符串,不能比较数字等其他形式的参数。

代码示例:

#include <string.h>
int main(void){
char *p="aBc";
char *q="Abc";
char *h="abc";
printf("strcmp(p,q):%d\n",strcmp(p,q));
printf("strcmp(p,h):%d\n",strcmp(p,h));
return 0;}
//结果:
//strcmp(p,q):32
//strcmp(p,h):-32


C++中字符串比较函数strcmp怎么用?