s1 != s2 returns true if s1 is not equal to s2. He is case sensitive!s1 < s2 returns true if s1 precedes s2 if they are ordered in dictionary order. If string s1 ="Nawaz" and string s2 = "nawaz" , then s1 < s2 will return true .s1 > s2 returns true if s1 comes after s2 if they are ordered in dictionary order.
As a general guide, the value of ascii upper letters is less than the value of ascii lower case: A less than A , B less than B , etc.
Therefore, the upper jaw is seen before the lower. By vocabulary, I had in mind the same thing. "A" to "A" . "Nawaz" to "Nawaz" , "Nawaz" , "Nawaz" , etc.
Compare character by character:
- If the ascii value of all characters in one line is equal to the ascii value of the corresponding characters in the other line, then the two lines are equal.
- If the ascii value of a character is less than the corresponding character in another line, then the first line is considered smaller. No need to compare all characters.
- If so far all the characters are equal and you have reached the end in the first line, while the second line still has some characters, then the first line is considered smaller. This means that
"Nawa" smaller than "Nawaz"
Hope this explanation helps you understand how comparisons for std::string .
Nawaz source share