Manipulators in cpp.
In this tutorial we learn Manipulators in cpp.These are the function that helps to modify the input/output stream.It does not change any value or data of the variable but it only modify the data as programmer wants.
Types of Manipulators:
1)Manipulator without argument:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
int main()
{
int m1,m2;
double f=3.14159;
clrscr();
cout<<"\nEnter two number:";
cin>>m1>>m2;
cout<<"\nDisplay the number:";
cout<<"\nN1:="<<m1;
cout<<"\nN2:="<<m2;
cout<<"\nN1="<<setw(8)<<m1<<endl;
cout<<"\nN2="<<setw(5)<<m2<<endl;
cout<<setfill('x')<<setw(10);
cout<<77<<endl;
cout<<setprecision(4)<<f;
getch();
return(0);
}
OUTPUT:
In this tutorial we learn Manipulators in cpp.These are the function that helps to modify the input/output stream.It does not change any value or data of the variable but it only modify the data as programmer wants.
Types of Manipulators:
1)Manipulator without argument:
- endl:This manipulator defined in ostream.It used to instead of using \n.It is use to enter the new line.
- ws:This manipulator use to ignore the all whitespaces in the line.It is defined in istream.
- ends:It includes the null character into the ostream.It is belonging in ostream.
- flush:It is also in ostream.It flushes output stream in the line.
- setw (val): It is used to sets the field width in output stream.
- setfill (x): It is used to fill the character ‘x’ on output stream.
- setprecision (val): It sets val as the new value for the precision of floating-point values.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
int main()
{
int m1,m2;
double f=3.14159;
clrscr();
cout<<"\nEnter two number:";
cin>>m1>>m2;
cout<<"\nDisplay the number:";
cout<<"\nN1:="<<m1;
cout<<"\nN2:="<<m2;
cout<<"\nN1="<<setw(8)<<m1<<endl;
cout<<"\nN2="<<setw(5)<<m2<<endl;
cout<<setfill('x')<<setw(10);
cout<<77<<endl;
cout<<setprecision(4)<<f;
getch();
return(0);
}
OUTPUT:
No comments:
Post a Comment