Professional Documents
Culture Documents
Discuss Manipulators
Discuss setfill() manipulator Discuss setw() manipulator Discuss setprecision() manipulator
Manipulators
Manipulator function are special stream functions that change
setfill(char):it can be used to fills the given character in the unused field
#include<iostream.h> #include<iomanip.h> #include<conio.h> void main() { int a=10,b=20; clrscr(); cout<<setfill('*'); cout<<setw(5)<<a<<setw(5)<<b<<endl; cout<<setfill('$'); cout<<setw(7)<<a<<setw(7)<<b<<endl; getche(); }
setprecision():This manipulator control display the number of digits after the decimal point for the floating numbers
#include<iostream.h> #include<conio.h> #include<iomanip.h> void main() { int a=10,b=3; clrscr(); float c=(float)a/b; //Casting Type cout<<setprecision(1)<<c<<endl; cout<<setprecision(2)<<c<<endl; cout<<setprecision(3)<<c<<endl; getche(); }
These are special functions that are used with cout statements for getting formatted outputs The ios base class contains member functions like width(),precision(),file(),setf() and unsetf() to display formatted output