The <iomanip>
header declares several I/O manipulators. An I/O
manipulator is a function object that can be used in a sequence of input
or output operators to manipulate the I/O stream. The manipulators are
simple wrappers for functionality that is available as member functions
of the ios_base
class, but
manipulators are simpler to use in some situations.
For example, to print formatted output, the following two code fragments are equivalent:
// Using manipulators std::cout << std::setw(16) << std::setprecision(12) << x; // Without manipulators std::cout.width(16); std::cout.precision(12); std::cout << x;
At a basic level, manipulators are easy to use. If you want to understand exactly how they work, perhaps to write your own, see Chapter 9 for a thorough discussion of I/O, including manipulators.
The return type of each manipulator is implementation-defined. For
the following function descriptions, this type is shown as
manip_t
.
Use a manipulator by applying it to a stream—that is,
out
<<
manip
, in
which out
is an instance of basic_ostream
, or
in
>>
manip
, in
which in
is an instance of basic_istream
. In the following function
descriptions, stream
refers to the input or
output stream to which the manipulator is being applied.