Use of manipulators in C++
Manipulators are stream functions available in iomanip.h header file and are used to change the default formats of input and output. These are used with stream insertion and extraction operators. They are used for defining a specified format of input and output. They provide features similar to that of ios member functions. Moreover, manipulators may be concatenated to result in a single statement. Some of the standard manipulators available in iomanip.h header file are endl, setw, setfill, hex, oct, dec, setprecision, flush, setiosflags etc. Manipulators are different from ios member functions as manipulator does not return the previous format state as is the case with ios member functions.
Consider the following example:
float x = 5.45;
Consider another example:
int n=52; //decimal number