* Manipulators in C++
These are operators that are used to format the data display. most commonly used operators are endl and setw.
Some of the more commonly used manipulators are given below:-
Table of Contents
1.endl manipulator
2.setw manipulator
3.setfill manipulator
1.endl manipulator
2.setw manipulator
3.setfill manipulator
endl Manipulator:-
endl is the line feed operator in C++. It acts as a stream manipulator whose purpose is to feed the whole line and then point the cursor to the beginning of the next line. We can use \n (\n is an escape sequence) instead of endl for the same purpose.
setw Manipulator:-
This manipulator sets the minimum field width on output.
syntax:- setw(x)
setfill Manipulator:-
This is used by the setw manipulator. If a value does not entirely fill a field, then the character specified in the setfill argument of the manipulator is used for filling the fields.
//cpp program to demonstrate manipulators..
http://codevidyalay.blogspot.com
#include<iomanip>
using namespace std;
int main()
{
int Basic=950, Allowance=95, Total=1045;
cout<<setw(10)<<"Basic"<<setw(10)<<Basic<<endl<<setw(10)<<"Allowance"<<setw(10)
<<Allowance<<endl<<setw(10)<<"Total"<<setw(10)<<Total<<endl;
return 0;
} // must include setw and endl.
INPUT/OUTPUT:-
Basic 950
Allowance 95
Total 1045