一、现在有一个问题描述:有两个字符串,要按照字典顺序比较它们的大小(注意所有的小写字母都大于所有的大写字母 )。
二、代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
string str1 = "apple";
string str2 = "banana";
int result1 = str1.compare(str2);
if (result1 < 0)
{
cout << "str1 小于 str2" << endl;
}
else if (result1 > 0)
{
cout << "str1 大于 str2" << endl;
}
else
{
cout << "str1 等于 str2" << endl;
}
return 0;
}