13.26 <iomanip>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.
The resetiosflags function clears the flag bits in mask for a stream. In other words, it performs the equivalent of stream.setf(ios_base::fmtflags(0), mask). See Alsosetiosflags function, ios_base in <ios>
The setbase function sets the conversion radix for a stream. In other words, it performs the equivalent of stream.setf(newbase, ios_base::basefield), in which newbase depends on base, as shown in Table 13-11. Notice that any value of a base other than 8, 10, or 16 is treated the same as 0.
See Alsoios_base in <ios>
The setfill function template sets the fill character for a stream to c. In other words, it performs the equivalent of stream.fill(c). See Alsoios_base in <ios>
The setiosflags function sets the flag bits in mask for a stream. In other words, it performs the equivalent of stream.setf(mask). See Alsoresetiosflags function, ios_base in <ios>
The setprecision function template sets the output precision for a stream to n. In other words, it performs the equivalent of stream.precision(n). See Alsoios_base in <ios>
The setw function template sets the output field width for a stream to n. In other words, it performs the equivalent of stream.width(n). See Also |