strcmp1.cpp
来自「c语言教程源码」· C++ 代码 · 共 26 行
CPP
26 行
//这个程序在本书所带软盘中。文件名为STRCMP1.CPP
//这个程序演示字符串比较函数strcmp()的各种比较结果。
#include <iostream.h>
#include <string.h>
void main(void)
{
char string1[] = "computer";
char string2[] = "computing";
char string3[20] = "computer";
char string4[] = "Computer";
char *string5 = "computre";
cout << "strcmp(string1, string2) = " << strcmp(string1, string2) << endl;
cout << "strcmp(string1, string3) = " << strcmp(string1, string3) << endl;
cout << "strcmp(string1, string4) = " << strcmp(string1, string4) << endl;
cout << "strcmp(string1, string5) = " << strcmp(string1, string5) << endl;
}
/*程序运行后的结果为:
strcmp(string1, string2) = -4
strcmp(string1, string3) = 0
strcmp(string1, string4) = 32
strcmp(string1, string5) = -13
*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?