I\'m following a tutorial for C++ and looking at strings and overloading with operators such as +=
, ==
, !=
etc. Currently I have a sim
The comparison operators implement lexicographic ordering of strings.
-=
and *=
are not defined for strings.
The less-than operator on strings does a lexicographical comparison on the strings. This compares strings in the same way that they would be listed in dictionary order, generalized to work for strings with non-letter characters.
For example:
"a" < "b"
"a" < "ab"
"A" < "a" (Since A has ASCII value 65; a has a higher ASCII value)
"cat" < "caterpillar"
For more information, look at the std::lexicographical_compare algorithm, which the less-than operator usually invokes.
As for -=
and *=
, neither of these operators are defined on strings. The only "arithmetic" operators defined are +
and +=
, which perform string concatenation.
Hope this helps!