C++ iomanip Library
C++ iomanip Functions
The <iomanip> library has functions that change how values are printed with cout, like the number of decimals, or the width of the output.
These functions are called manipulators, because you put them in the output with <<, and they change the output that comes after them.
| Function | Description |
|---|---|
| setprecision() | Sets the number of digits (or decimals, with fixed) to print for decimal numbers |
| setw() | Sets the width (number of characters) of the next value that is printed |
| setfill() | Sets the character that is used to fill the empty space when you use setw() |
| setbase() | Sets the number base (8, 10 or 16) for whole numbers |
| setiosflags() | Turns on one or more format flags, like ios::fixed |
| resetiosflags() | Turns off one or more format flags, like ios::fixed |
| put_time() | Prints a date and time from a tm structure in a chosen format |
| get_time() | Reads a date and time in a chosen format into a tm structure |
Related Manipulators
These manipulators are not part of <iomanip>, but they are often used together with it. They are found in <iostream>:
| Manipulator | Description |
|---|---|
| fixed | Shows decimal numbers with a fixed number of decimals (see Decimal Precision) |
| scientific | Shows decimal numbers in scientific notation, like 1.23e+06 |
| left | Aligns the output to the left when you use setw() |
| right | Aligns the output to the right when you use setw() (this is the default) |
| showpoint | Always shows the decimal point, even for numbers like 9.0 |
| boolalpha | Prints true and false instead of 1 and 0 |
Related Pages
C++ Decimal Precision Tutorial