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.
98 > 97, that's it. Why would you add up the ASCII codes of the letters anyway?elsebranch is wrong. If s1 is not greater than s2, it may also be that s1 is equal to s2.std::stringis an operation on a much higher abstraction level.