Section 7.13 string
s are comparable
word
is equal to "banana"
.The other comparison operations are useful for putting words in alphabetical order.
word
relative to "banana"
.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.
Checkpoint 7.13.2.
"dog" < "Dog";
- 1
- d is greater than D
- 0
- Yes, upper case is less than lower case according to the ordinal values of the characters.
- They are the same word
- C++ is case sensitive meaning that upper case and lower case characters are different.
Checkpoint 7.13.3.
Checkpoint 7.13.4.
You have attempted 1 of 4 activities on this page.