#include<iostream>
#include<stdlib.h>
#include<string>
using namespace std;
/*
3.1.6 string字符串比较
字符串比较是按字符的ASCII码进行对比
= 返回 0
> 返回 1
< 返回 -1
int compare(const string &s) const; //与字符串s比较
int compare(const char *s) const; //与字符串s比较
*/
void test1()
{
string s1 = "hello";
string s2 = "hello";
if(s1.compare(s2) == 0)
{
cout << "s1==s2" << endl;
}
s1 = "xello";
s2 = "hello";
if(s1.compare(s2) == 0)
{
cout << "s1==s2" << endl;
}
else if(s1.compare(s2) > 0)
{
cout << "s1 > s2" << endl;
}
else
{
cout << "s1 < s2" << endl;
}
}
int main()
{
test1();
//字符串对比主要是用于比较两个字符串是否相等,判断谁大谁小的意义并不是很大
system("pause");
return 0;
}