I wanted to sort a vector of strings in terms of their ASCII order and my first try was using < >
operators.I got some weird results and then I found compare
function for strings in c++ and completed my task.
But after that when I was reading c++ reference, It was written that > <
operators are using the exact compare
function for strings! So why do I get different results like this:
int main(){
cout << ("ali" > "Zahra") << endl;
string a = "ali";
cout << a.compare("Zahra");
}
the output is
0
461569
which means in the comparison with >
operator "ali"
comes first but with compare
function "Zahra" comes first (which is more sensible because of ASCII).
So my question is how does these operators work for strings?