功能描述:
- 字符串之间的比较
比较方式:
- 字符串比较是按照ASCII码进行对比
= 返回 0
> 返回 1
< 返回 -1
注:字符串对比主要是用于比较两者是否相等
函数原型:
int compare(const string& s) const; //与字符串s比较int compare(const char *s) const; //与字符串s比较
// 字符串比较void test01(){string str1 = "xhello";string str2 = "hello";int res = str1.compare(str2);if (res == 0){cout << "str1 == str2" << endl;}else if (res > 0){cout << "str1 > str2" << endl;}else{cout << "str1 < str2" << endl;}}int main(void){test01();system("pause");return 0;}
