Manipulators are keywords that are used for doing something to change the way the output appears on the screen. |
|
They are only for presentation purpose; just to make your program output look better. |
|
One of the most commonly used manipulators is endl. This is used to end the line and leave the next line blank. |
|
endl is used along with cout. You cannot use endl separately. |
|
The iomanip.h header file is used to include the manipulators |
|
Let’s check out an example program: |
|
 |
|
Out put of the program |
|
 |
|
The above program will display the line Hi, this is a test program. After this line there is an endl. |
|
Hence the compiler will end the current line and leave the next line blank. The next cout statement is again endl. |
|
This means another line is left blank. The next statement starts with an endl. Hence a third line is left blank before printing the last sentence on the screen. |
|
Don’t use double quotes on endl. |
|
The above program could be easily written as follows: |
|
cout<< “Hi, this is a test program”<< endl<<endl<<endl<< “You should see three empty lines above this”; |
|
The output will be the same ,but We just wanted to illustrate that ways in which endl could be use. |