Formatting with cout

The ostream insertion operators convert values to text form. By default, they format values as follows:

• A type char value, if it represents a printable character, is displayed as a character in a field one character wide.

• Numeric integer types are displayed as decimal integers in a field just wide enough to hold the number and, if present, a minus sign.

• Strings are displayed in a field equal in width to the length of the string.

The default behavior for floating-point types has changed. The following are the differences between ancient and current C++ implementations:

New style— Floating-point types are displayed with a total of six digits, except that trailing zeros aren’t displayed. (Note that the number of digits ...

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.