When a C++ program that includes the iostream classes starts, four objects are created and initialized: NOTE: The iostream class libr...
When a C++ program that includes the iostream classes starts, four objects are created and initialized:
NOTE: The iostream class library is added automatically to your program by the compiler. All you need to do to use these functions is to put the appropriate include statement at the top of your program listing.
- cin (pronounced "see-in") handles input from the standard input, the keyboard.
- cou (pronounced "see-out") handles output to the standard output, the screen.
- cer (pronounced "see-err") handles unbuffered output to the standard error device, the screen. Because this is unbuffered, everything sent to cerr is written to the standard error device immediately, without waiting for the buffer to fill or for a flush command to be received.
- clo (pronounced "see-log") handles buffered error messages that are output to the standard error device, the screen. It is common for this to be "redirected" to a log file, as described in the following section.
Redirection
Each of the standard devices, input, output, and error, can be redirected to other devices. Standard error is often redirected to a file, and standard input and output can be piped to files using operating system commands.
New Term: Redirecting refers to sending output (or input) to a place different than the default. The redirection operators for DOS and UNIX are (<) redirect input and (>) redirect output.
Piping refers to using the output of one program as the input of another.
DOS provides rudimentary redirection commands, such as redirect output (>) and (>)redirect input (<). UNIX provides more advanced redirection capabilities, but the general idea is the same: Take the output intended for the 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.
Redirection is more a function of the operating system than of the iostream libraries. C++ just provides access to the four standard devices; it is up to the user to redirect the devices to whatever alternatives are needed.