Next: Unions Up: Introduction to C++ Previous: The Increment Operator

Printing

The simplest way to do printing in C++ is to use the shift operator ``<<''. (This facility does not exist in C.) First a destination for the printing is indicated, which may be an fstream or iostream variable, or the constants cout (standard output) or cerr (standard error output). The material to be printed is then directed to the destination. A line of text may be terminated by ``printing'' the constant endl. Thus,


cout << "I = " << i << endl;

produces the output


I = 14

on the terminal screen, while


o << "I = " << i << endl;

produces the same output on the file indicated by the fstream variable o.


walter@
Wed Aug 10 11:53:26 PDT 1994