For convenience, manipulators provide a way to change certain properties of streams, or otherwise affect them, in the middle of expressions involving `<<' or `>>'. For example, you might write
cout << "|" << setfill('*') << setw(5) << 234 << "|";
to produce `|**234|' as output.
Skip whitespace.
Flush an output stream. For example, `cout << ... <<flush;' has the same effect as `cout << ...; cout.flush();'.
Write an end of line character `\n', then flushes the output stream.
Write `\0' (the string terminator character).
Manipulator: setprecision (int signif)
You can change the value of ios::precision
in `<<'
expressions with the manipulator `setprecision(signif)'; for
example,
cout << setprecision(2) << 4.567;
prints `4.6'. Requires `#include <iomanip.h>'.
You can change the value of ios::width
in `<<' expressions
with the manipulator `setw(n)'; for example,
cout << setw(5) << 234;
prints ` 234' with two leading blanks. Requires `#include <iomanip.h>'.
Manipulator: setbase (int base)
Where base is one of 10
(decimal), 8
(octal), or
16
(hexadecimal), change the base value for numeric
representations. Requires `#include <iomanip.h>'.
Select decimal base; equivalent to `setbase(10)'.
Select hexadecimal base; equivalent to `setbase(16)'.
Select octal base; equivalent to `setbase(8)'.
Manipulator: setfill (char padding)
Set the padding character, in the same way as ios::fill
.
Requires `#include <iomanip.h>'.