Re: About stdin & stdout

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Carl Daniel [VC++ MVP] (cpdaniel_remove_this_and_nospam_at_mvps.org.nospam)
Date: 03/19/04


Date: Thu, 18 Mar 2004 22:12:12 -0800

Robe wrote:
> Hi,
>
> I need to know how does work exactly the "stdin" and "stdout". I
> guess that this is a mechanism used by the operating system and not
> by Visual C++.

stdin and stdout are variables defined in and managed by the C runtime
library. They're actually just constants (0 and 1 or 1 and 2 - I don't
recall) that correspond to pre-opened files. The C runtime library startup
code takes care of connecting them to the OS standard input and standard
output streams.

> Where can I get a good information about this mechanism.

Any C or Unix programming book will talk about stdin and stdout. The VC++
documentation, including what's available online on MSDN describes them from
a VC++ perspective. The CRT source code, which is included with VC++ can be
examined for any really down and dirty questions.

If you're really after the Win32 (OS level) Standard Input and Standard
Output, you might try looking up GetStdHandle() on MSDN or in the VC++ help
as a starting point.

-cd



Relevant Pages

  • Re: stdin and stdout
    ... > I have read about stdin and stdout being standard input and output ... First, all std* streams ... Similarily stdout and stderr are output only. ...
    (comp.lang.c)
  • Re: Forth stdin and stdout
    ... which takes stdin and stdout. ... Win32for and iForth. ... the notes in the ./dfwforth/bugs.frt file on redirection. ...
    (comp.lang.forth)
  • Re: why standard files?
    ... opened namely STDIN, STDOUT, STDERR. ... an output data stream that the program can write it's normal ...
    (comp.lang.c)
  • Re: How to automatically flush stdout when a read from stdin occurs.
    ... like stdin and stdout not redirected ... Output streams that refer to terminal devices are always line ... I believe that on systems with automatic flush behavior, ...
    (comp.unix.programmer)
  • Re: man-in-the-middle translation of input
    ... program that spawns the game, forwards its output to stdout, reads my input ... replaces my input by a series of valid game commands. ... write to stdout, I couldn't find a way to read from stdin, preprocess the ... input and feed it through a pipe to the child. ...
    (comp.unix.programmer)