Sunday, 6 November 2011

What is a stream? in C programming

What is a stream?
A stream is a continuous series of bytes that flow into or out of your program. Input and output from devices
such as the mouse, keyboard, disk, screen, modem, and printer are all handled with streams. In C, all streams
appear as files—not physical disk files necessarily, but rather logical files that refer to an input/output source.
The C language provides five “standard” streams that are always available to your program. These streams
do not have to be opened or closed. These are the five standard streams
---------------------------------------------------------------
Name              Description                      Example
---------------------------------------------------------------
stdin                Standard Input                  Keyboard
stdout              Standard Output               Screen
stderr               Standard Error                  Screen
stdprn              Standard Printer                LPT1: port
stdaux              Standard Auxiliary             COM1: port
---------------------------------------------------------------
Note that the stdprn and stdaux streams are not always defined. This is because LPT1: and COM1: have
no meaning under certain operating systems. However, stdin, stdout, and stderr are always defined. Also,
note that the stdin stream does not have to come from the keyboard; it can come from a disk file or some
other device through what is called redirection. In the same manner, the stdout stream does not have to
appear on-screen; it too can be redirected to a disk file or some other device. See the next FAQ for an
explanation of redirection.

Cross Reference:

IV.3: How do you redirect a standard stream?
IV.4: How can you restore a redirected standard stream?
IV.5: Can stdout be forced to print somewhere other than the screen?

No comments:

Post a Comment