Reputation: 135
Below code produces different results:
string d = "d"; string abc = "abc";
d > abc evaluates to true.
How do they produce different outputs?
Upvotes: 1
Views: 46
Reputation: 701
"d"
is not a std::string
. It is a const char *
. As such, when you do string d = "d"
, you set a string to the const char *
of {'d', '\0'}
. Then when you compare it, the std::string operator>
is used instead of the version for a const char *
.
Upvotes: 1