strings are comparable¶
All the comparison operators that work on
also work on
Take a look at the active code below, which checks to see if
The other comparison operations are useful for putting words in alphabetical order.
The active code below uses comparison operators to determine the ordering
word relative to
You should be aware, though, that the
string class does not handle
upper and lower case letters the same way that people do. All the upper
case letters come before all the lower case letters. As a result,
Your word, Zebra, comes before banana.
A common way to address this problem is to convert strings to a standard format, like all lower-case, before performing the comparison. The next sections explains how. I will not address the more difficult problem, which is making the program realize that zebras are not fruit.
For the following questions, remember that in C++
1 means true and
0 means false.