C++语言程序设计

strcmp：比较两个字符串firststring和secondstring。
strcmp函数应用举例
原型：int strcmp(const char firststring[], const char secondstring);
功能：比较两个字符串firststring和secondstring
例程：

| 例6-19

#include <iostream.h>
#include <string.h>
void main(void)
{
char buf1[] = "aaa";
char buf2[] = "bbb";
char buf3[] = "ccc";
int ptr;
ptr = strcmp(buf2,buf1);
if(ptr > 0)
cout<<"Buffer 2 is greater than buffer 1"<<endl;
else
cout<<"Buffer 2 is less than buffer 1"<<endl;
ptr = strcmp(buf2,buf3);
if(ptr > 0)
cout<<"Buffer 2 is greater than buffer 3"<<endl;
else
cout<<"Buffer 2 is less than buffer 3"<<endl;
}

运行结果：
Buffer 2 is less than buffer 1
Buffer 2 is greater than buffer 3