Manipulators
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.
# include<iostream.h>
# include<conio.h>
# include<iomanip.h>
void main( )
{
clrscr( );
cout<< "Hi, this is a test
program"<<endl;
cout<<endl;
cout<<endl<<"You should see
three empty lines above this";
getch( );
}
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 I just wanted to
illustrate that ways in which endl could be used.
Another manipulator is the setw manipulator. I'll write about this later.
The next section is on : Variables (global, local)
or you can
go to the Contents
Copyright © 2002 Sethu Subramanian All rights reserved.