- cin(pronounced “see-in”) handles input from the standard input, the keyboard.
- cout(pronounced “see-out”) handles output to the standard output, the console
screen. - cerr(pronounced “see-err”) handles unbuffered output to the standard error
device, the console screen. Because this is unbuffered, everything sent to cerris
written to the standard error device immediately, without waiting for the buffer to
fill or for a flush command to be received. - clog(pronounced “see-log”) handles buffered error messages that are output to the
standard error device, the console screen. It is common for this to be “redirected”
to a log file, as described in the following section.
Redirection of the Standard Streams ..................................................................
Each of the standard devices, input, output, and error, can be redirected to other devices.
The standard error stream (cerr) is often redirected to a file, and standard input (cin)
and output (cout) can be piped to files using operating system commands.
Redirecting refers to sending output (or input) to a place different than the default.
Redirection is more a function of the operating system than of the iostreamlibraries.
C++ just provides access to the four standard devices; it is up to the user to redirect the
devices to whatever alternatives are needed.
The redirection operators for DOS, the Windows command prompt, and Unix are (<)
redirect input and (>) redirect output. Unix provides more advanced redirection capabili-
ties than DOS or the standard Windows command prompt; however, the general idea is
the same: Take the output intended for the console screen and write it to a file, or pipe it
into another program. Alternatively, the input for a program can be extracted from a file
rather than from the keyboard.
598 Day 17
The iostreamclass library is added automatically to your program by the
compiler. All you need to do to use these functions is to put the appropriate
includestatement at the top of your program listing:
#include <iostream>
This is something you have been doing in your programs already.
NOTE
NOTE Piping refers to using the output of one program as the input of another.