strcmp——字符串的比較
逐個字符比較,直到遇到不同的,或者到了結尾。
當s1<s2時,返回值<0 ; 當s1=s2時,返回值=0 ; 當s1>s2時,返回值>0
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char *s1="China",*s2="Yinshiyong", *s3="China";
int x1, x2;
x1 = strcmp(s1, s2);
x2 = strcmp(s1, s3);
cout<<x1<<endl<<x2<<endl;
}

用這個函數我們可以比較兩個字符串的大小。
這個是比較常用的用法。
posted on 2011-11-22 21:48 More study needed. 閱讀(352) 評論(0) 收藏 舉報
浙公網安備 33010602011771號