I am not sure how to form this question, since english isn't my primary language. . .
What is the process behind comparing two strings?
For example, how does a computer, on which logic, compare two strings?
#include <iostream>
#include <string>
int main()
{
std::string s1 {"b"};
std::string s2 {"abc"};
if(s1 > s2)
{
std::cout << s1 << " > " << s2;
}
else std::cout << s2 << " > " << s1;
return 0;
}
ouput: b > abc
How does a computer come up with this logic (even though it is correct).
I imagined computers logic to be converting chars into integers then comparing them by size, which is not the case here since if it was
b > abc
would be treated like 98 > 97 + 98 + 99
which is incorrect.