C++ Manipulators managing output with manipulators
The header file iomanip provides a set of functions called manipulators which can be used to the manipulate the output formats. They provide the same features as that of the ios(Input output system) member functions and flags. Some manipulators are more convenient to use than their counterparts in the class(Input output system) ios. such that, two or more manipulators can be used as a chain in one statement as shown below:
cout << manip1 << manip2 << manip3 << item;
cout << manip1 << item1 << manip2 << item2;
|
This kind of concatenation is useful when we want to display several columns of output. The most commonly used manipulators are shown in Table10.6. The table also gives their meaning and equivalents. To access these manipulators, we must include the file iomanip in the program.
Types of Manipulators
Manipulators without arguments:
The important manipulators defined by the header IOStream library are provided below.
endl: It is defined in header ostream. It is used for enter a new line and end1 after entering a
new line it flushes the output stream.
ws: It is defined in header istream and is used for ignore the whitespaces in the string sequence.
ends: It is also defined in header ostream and it add a null character into the output stream.
It works with std::ostrstream, whenever the output buffer needs to be null character-terminated to be processed as a C string.
flush: It is also defined in header ostream and this flushes the output stream,
i.e. this forces all the output written on the screen. And without flush,
the output would be the same, but may be not appear in real-time.