My Blog List

Sunday, December 8, 2019

Manipulators in cpp

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:
  • 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.
 2)Manipulators with Arguments: 

  • 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. 
code:

#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

Multiple Inheritance in C++.

     In this tutorial Multiple Inheritance in c++. On the basis of Inheritance concept the another type of inheritance is the Multiple I...