What are the examples on usages of std::string
class with !=
, >
, and <
?
s1 != s2
returns true if s1 is not equal to s2. It's case sensitive!s1 < s2
returns true if s1 comes before s2 if they're arranged 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're arranged in dictionary order.As a general guideline, ascii value of uppercases is smaller than the ascii value of lowercases: A
is smaller than a
, B
is smaller than b
, and so on.
So uppercases are considered before the lowercases. By dictionary order, I meant the same thing. "A"
is before "a"
. "Nawaz"
is before "nawaz"
, "nAwaz"
, "nAWAZ"
etc.
Compare character by character:
"Nawa"
is smaller than "Nawaz"
I hope this explanation helps you understanding how comparisons work for std::string
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With