OOPortal   Tweet
J2EEOnline RationalDB

Programming C++  «Prev  Next»
Lesson 2Output
Objective Examine simple output of a C++ program.
Programs must communicate to be useful. Let us look at a C++ program that prints the phrase C++ is an improved C onscreen.
Program dissection
Move your mouse cursor over the highlighted lines of code below to receive tooltip information of their function.

C++ Output
Rewriting the program
While the above program is correct, we can simplify the program as follows:
//A first C++ program illustrating output
#include <iostream.h>
int main()
   cout << "C++ is an improved C." << endl;
   return (0);
We use the put to operator (<<) twice with cout. Each time we use << with cout, printing continues from the position where it previously left off.
The identifier endl flushes the output stream and adds a new line. The endl identifier is called a manipulator.
A manipulator is a value or function that has a special effect on the stream it operates on. For a complete list of C++ I/O manipulators, click the Help button on the toolbar.