Following are the standard manipulators normally used in the stream classes:
•endl
•hex, dec, oct
•setbase
•setw
•setfill
•setprecision
•ends
•ws
•flush
(a) Endl-the endl is an output manipulator to generate a carriage return or line feed character. Theendl may be used several times in a C++ statement.
For example,
(1)
cout << “ a “ << endl << “b” << endl;
(b) Setbase() The setbase() manipulator is used to convert the base of one numeric value into another base. Following are the common base converters in C++.
dec – decimal base (base = 10)
hex – hexadecimal base (base = 16)
(c) Setw ()
The setw ( ) stands for the set width. The setw () manipulator is used to specify the minimum number of character positions on the output field a variable will consume.
The general format of the setw manipulator function is
setw( int w )
Which changes the field width to w, but only for the next insertion. The default field width is 0.
For example,
cout << setw (1) << a << endl;
cout << setw (10) << a << endl;
(d) Setfill()
The setfill ( ) manipulator function is used to specify a different character to fill the unused field width of the value.
The general syntax of the setfill ( ) manipulator is
setfill( char f)
which changes the fill character to f. The default fill character is a space.
For example,
setfill ( ‘ . ’ ) ; / / fill a dot ( . ) character
setfill ( ‘ * ’ ) / / fill a asterisk (*) character
(e) Setprecision()
The setprecision ( ) is used to control the number of digits of an output stream display of a floating point value. The setprecision ( ) manipulator prototype is defined in the header file <iomanip.h>.
The general syntax of the setprecision manipulator is
Setprecision (int p)
Which sets the precision for floating point insertions to p. The default precision is 6 eg:- 0.0000001
(f) Ends
The ends is a manipulator used to attach a null terminating character (‘’) at the end of a string. The ends manipulator takes no argument whenever it is invoked. This causes a null character to the output.
(g) Ws
The manipulator function ws stands for white space. It is used to ignore the leading white space that precedes the first field.
1.Noskipws
Skipws
(h) Flush The flush member function is used to cause the stream associated with the output to be completed emptied.
For input on the screen, this is not necessary as all output is flushed automatically. However, in the case of a disk file begin copied to another, it has to flush the output buffer prior to rewinding the output file for continued use. The function flush ( ) does not have anything to do with flushing the input buffer.