These operators do not perform lexicographical comparisons and seem to provide inconsistent results.
#include <iostream>
int main () {
std::cout << ("70" < "60") << '\n';
std::cout << ("60" < "70") << '\n';
return 0;
}
and
#include <iostream>
int main() {
std::cout << ("60" < "70") << '\n';
std::cout << ("70" < "60") << '\n';
return 0;
}
both print
1
0
The same holds true for std::less<>()
. However, std::less<std::string>()
provides the correct lexicographical comparison. What is the reason for this behaviour?
Are the comparisons shown above comparing the addresses of char arrays?