Formatting Cout output in C++ using
iomanip.h header file:
Note:
- iomainp of standard form is “Input and Output Manipulation” header file.
- It is used to align the sentence or output on output screen.
- Standard methods are,setw(),setfill() and setprecision().
1. setw():
- This function is used to set the space on the output.
- Setw means set width.
cout<<”Some sentence”<<setw(size);
2.setfill():
- This is function is used to display number of symbols with given width.
cout<<”Some sentence”<<setfill(any
symbol)<<setw(size);
3.setprecision()
- This fuction is used to take decimal value based on its size.
cout<<”Some sentence”<< setprecision(size)
<< number or variable;
Example program:
Note:
- endl is used to enter purpose or goto next line in the output screen(It mainly used for, when double-quotes do not use in cout function and that output of result needs to go to the next line means we give endl).
- \n – it is also used to go next line if give \n then must be within "".
No comments:
Post a Comment