#include <iostream>
#include <algorithm>
using namespace std;
bool cmp (char c1, char c2)
{
return tolower(c1)<tolower(c2);
}
int main (void)
{
char first[]="Apple"; // 5 letters
char second[]="apartment"; // 9 letters
if (lexicographical_compare(first,first+5,second,second+9))
{
cout << first << " is less than " << second << endl;
}
else if (lexicographical_compare(second,second+9,first,first+5))
{
cout << first << " is greater than " << second << endl;
}
else
{
cout << first << " and " << second << " are equivalent\n";
}
if (lexicographical_compare(first,first+5,second,second+9,cmp))
{
cout << first << " is less than " << second << endl;
}
else if (lexicographical_compare(second,second+9,first,first+5,cmp))
{
cout << first << " is greater than " << second << endl;
}
else
{
cout << first << " and " << second << " are equivalent\n";
}
return 0;
}
lexicographical_compare的用法
最新推荐文章于 2022-12-20 08:30:00 发布