字符串的比较是按字符的ASCII码进行对比, =返回0 >返回 1 <返回-1
函数原型:
#include <iostream>
using namespace std;
#include <string>
void test01()
{
string str1="hello";
string str2="hello";
if(str1.compare(str2)==0)
{
cout<<"str1和str2相等"<<endl;
}
else if(str1.compare(str2)>0)
{
cout<<"str1大于str2"<<endl;
}
else
{
cout<<"str1小于str2"<<endl;
}
}
int main()
{
test01();
return 0;
}