Go to the first, previous, next, last section, table of contents.

Changing stream properties using manipulators

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.

Manipulator: ws
Skip whitespace.

Manipulator: flush
Flush an output stream. For example, `cout << ... <<flush;' has the same effect as `cout << ...; cout.flush();'.

Manipulator: endl
Write an end of line character `\n', then flushes the output stream.

Manipulator: ends
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>'.

Manipulator: setw (int n)
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>'.

Manipulator: dec
Select decimal base; equivalent to `setbase(10)'.

Manipulator: hex
Select hexadecimal base; equivalent to `setbase(16)'.

Manipulator: oct
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>'.


Go to the first, previous, next, last section, table of contents.