... Objects and Displaying Them with cout
and Operator <<
Lines 8–10 create three string
objects:
s1
is initialized with the literal"happy"
,s2
is initialized with the literal" birthday"
ands3
uses the defaultstring
constructor to create an emptystring
.
Lines 13–14 output these three objects, using cout
and operator <<
, which the string
class designers overloaded to handle string
objects.
Comparing string
Objects with the Equality and Relational Operators
Lines 15–21 show the results of comparing s2
to s1
by using class string
’s overloaded equality and relational operators, which perform lexicographical comparisons (that is, like a dictionary ordering) using the numerical values of the characters in each string
(see Appendix B, ASCII Character ...
Get C++ How to Program, 10/e now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.