All input and output is performed with streams.
Here's the concept:
- A stream is a sequence of bytes that flow from a source to a
- In a program, we read information from an input stream and
write information to an output stream
- A program can manage multiple streams simultaneously, some for input,
some for output.
Text streams are sequences of characters that are organized into lines,
where each line consists of 0 or more characters and ends with the
newline character, '\n'.
When execution begins, three standard streams are connected to the
- The standard input stream, stdin, is connected to the keyboard
- The standard output stream, stdout, is connected to the screen
- The standard error stream,stderr, is connected to the screen
Some operating systems, including both UNIX and DOS, allow the standard
input stream and the standard output stream to be redirected
to other devices.
Example: You can use UNIX redirection to let the contents of the file,
datafile.dat, feed into the stdin stream, rather than input from the
keyboard, by using the following command :
a.out < datafile.dat
The standard error stream is typically used to print errors.
- It's useful to keep this separate from stdout
- For example, you might want to use redirection to send your
program's output to a file, but display any errors on the
user's screen so they will be noticed.
Last Modified - Tuesday, 22-Aug-2006 07:14:05 EDT