The Overloaded <<
Operator
Most often, this book has used cout
with the <<
operator, also called the insertion operator:
int clients = 22;cout << clients;
In C++, as in C, by default the <<
operator is used as the bitwise left-shift operator (see Appendix E, “Other Operators”). An expression such as x<<3
means to take the binary representation of x
and shift all the bits three units to the left. Obviously, this doesn’t have a lot to do with output. But the ostream
class redefines the <<
operator through overloading to output for the ostream
class. In this guise, the <<
operator is called the insertion operator instead of the left-shift operator. (The left-shift operator earned this new role through its visual aspect, which suggests a flow of ...
Get C++ Primer Plus 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.