Output with cout

C++, we've said, considers output to be a stream of bytes. (If you use wostream, they may be 16-bit wide bytes, but bytes nonetheless.) But many kinds of data in a program are organized into larger units than a single byte. An int type, for example, may be represented by a 2- or 4-byte binary value. And a double value may be represented by 8 bytes of binary data. But when you send a stream of bytes to a screen, you want each byte to represent a character value. That is, to display the number -2.34 on the screen, you should send the five characters -, 2, ., 3, and 4 to the screen, and not the internal 8-byte floating-point representation of that value. Therefore, one of the most important tasks facing the ostream class is converting ...

Get The Waite Group's C++ Primer Plus, Third Edition 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.