Tuesday 11 September 2012

C++ ( Tutorials V )


Manipulators
There are many stream-formatting functions available but it is a little tedious to use them.Manipulators duplicate these functions and make it easier to carry out stream-formatting operations. Usually it is the output (what we display on the screen) that needs to be formatted to suit our needs. In this case, ‘cout’ is the stream. One of the most commonly used manipulators is ‘endl’. This is used to end the current line and go to the next line. You cannot use ‘endl’ separately. All the manipulators have to operate on streams. Manipulators that do not require any arguments are defined in the iostream.h header (manipulators with arguments are defined in the iomanip.h header file).
Let's check out an example program.

# include<iostream.h>
int main( )
{
cout<< "Hi, this is a test program"<<endl;
cout<<endl;
cout<<endl<<"You should see three empty lines above this";
return 0;
}


The output will be:

Hi, this s a test program

0 comments:

Post a Comment