c++ manipulators
what is manipulators in c++?
simple manipulator is used to change the format of the output in c++ program.
when we use manipulator in c++ program then we able to change the output style of the program. The manipulator is the most important way to control or change the output style of the program in c++. The data is manipulated by the choices of the programmer's display means what type of display the programmer want to display the output of the program in c++.
c++ language provide different type of manipulator to used and change the output display style with your own choice. We can used different manipulator to change the display of the output means cout of the program.
what are the different types of manipulator in c++?
There are many manipulators in c++ some of them are as follow.
- 'endl' manipulator.
- 'setw' manipulator.
- 'setprecision' manipulator.
- 'fixed' manipulator.
- 'showpoint' manipulator.
- 'endl' manipulator.
The endl means end of line which is used to insert a new line in a program. It also used to move the cursor at the beginning of the next line. it works similar to '\n' . it does not requires any parameter.
example cout<<"hello"<<endl<<"world"; the output of the program is hello world.- 'setw' manipulator
The setw manipulator stand for set width. This manipulator is used to display the value of the expression in specified columns. the value of expression can be string or number.if the value of the expression is less than the number of the specified column then the additional columns are left blank specified column.
- 'setprecision' manipulator.
The 'setprecision' manipulator is used to set the number of digits. to be display after decimal point . it is applied to all sub sequent floating point numbers written to that output stream. the value is rounded with the use of this manipulator.
examplen=0.33cout<<setprecision(3);
output of the program is 0.333
- fixed manipulator
The fixed manipulator is used to control the output of the floating point number.it display the floating pint numbers in a fixed decimal format.the following statement sets the output of the floating point number in a fixed decimal format.
cout<<fixed;
All the floating point number after the above statement are displayed in the fixed decimal floating point. - showpoint manipulator
in program the floating point decimal point does not show if the floating point is zero then the user need the floating point decimal part zero the programmer use the showpoint manipulator in program to show the decimal point zero.
cout<<showpoint;
- 'setw' manipulator
- 'setprecision' manipulator.
- fixed manipulator
- showpoint manipulator