Fixed width fields in c++

setw() is the I/O Manipulator  which is used to sets the width of the fields.

#include<iomanip.h> header file is used for manipulators.

It takes the size of the field(in number of character)as parameter.

 

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>  //used for manipulators

int main()
{
int age=20;
int rollno=9101;
clrscr();
cout<<setfill('#');   //used for fill the space
cout<<setw(4)<<age<<setw(6)<<rollno<<endl;
cout<<setw(6)<<age<<setw(8)<<rollno;
getch();
return 0;
}

fixed width fields
Explaination...
In above example we use setw(4) means the width of the variable (age)print is 4 but the value in variable age is 2
this will set the width by using # symbol.