函数原型:
int compare(const string &s)const;//与字符串s比较
int compare(const char*s)const;//与字符串s比较
//string字符串的比较:通常比较是否相等
//1、通过比较ASCLL码值的大小
//2、等于 返回0 大于 返回 1 小于返回 -1
#include<iostream>
using namespace std;
#include<string>
void test01()
{
string str1 = "hello";
string str2 = "allo";
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();
system("pause");
return 0;
}