Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Manipulators in C++

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 204
    Comment on it

    These are the operators that are used to format data display.

    (i) end l manipulator

    when it is used is an output statement,causes a line feed to be inserted. It has the same effect as       using new line character "n".

    e.g. the statement
     

    cout<<"m="<<m end l;
    
    cout<<"n="<<n end l;
    
    cout<<"p="<<p end l;

    would cause three lines of output, one for each variable. If values of the variable are assumed as

    2597,14 and 175 respectively, then output will appear as follows:

    2 5 9 7

    this is the value of m.

    1 4

    this is the value of n.

    1 7 5

    this is the value of p.

    This is not an ideal output but it should appear rather as follows:

    2 5 9 7

    this is the value of m.

    1 4

    this is the value of n.

    1 7 5

    this is the value of p.

    (ii) set w manipulators

    It is used as follows:

    cout<<set w(5)<<sum<<end l;

    Manipulator set w(5) specifies a field width 5 for printing value of the variable sum. This value is right

    justified within the field as shown below:

        3 4 5

    Use of manipulators.
     

    # include<iostream.h>
    
    #include<iomanip.h>// to set w
    
    main()
    
    { 
    
        int Basic=950, Allowance=95
    
        Total=1045;
    
    cout<< set w (10)<<"Basic" << set w (10) << Basic << end l
    
    << set w (10)<<"Allowances" << set w (10) << Allowances << end l
    
    << set w (10)<<"Total" << set w (10) << Total << end l
    
    

    Output of this program is

    Basic 950

    Allowances 95

    Total 1045

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: