Coupon Accepted Successfully!


Formatting Output

  • It is used in developing output, which can be easily understood by the user.
  • Creating formatted output is common programming need to improve user interface and it is easier to read any debugging messages.
  • There are various set of basic I/O manipulators in C++.
  • To implement manipulators the header file iomanip.h is included.
    • ​Example


  • The various manipulators are
    • setw()
    • setprecision()
    • setfill()

setw() manipulator

  • It takes one argument and the width of the next output using the insertion operator
    • Example

cout<<setw(10) <<"a";


The output will be

Bbbbbbbbb a

It displays the character after 9 blank spaces.

setprecision() manipulator

  • Set precision function is used to set the maximum number of digits that are displayed for a number.
    • Example

cout<< setprecision(6)<< 15.2363636;

The output will be



setfill() manipulator

  • It is used after setw manipulator.
  • It the value does not fill a field, then the character specified by the setfill command is filled in the blank field.
    • Example

cout<<setw(10) <<setfill('*') <<10 <<30<< endl;

The output will be


Test Your Skills Now!
Take a Quiz now
Reviewer Name