曲径通幽论坛

标题: stderr, stdin, stdout - standard I/O streams [打印本页]

作者: beyes    时间: 2008-11-16 23:08
标题: stderr, stdin, stdout - standard I/O streams
NAME
[blockquote]stderr, stdin, stdout - standard I/O streams[/blockquote]SYNOPSIS
[blockquote]#include <stdio.h>

extern FILE *stderr, *stdin, *stdout;

[/blockquote]DESCRIPTION
A file with associated buffering is called a stream and is declared to be a pointer to a defined type FILE. The fopen()functionshall create certain descriptive data for a stream and return a pointerto designate the stream in all further transactions. Normally, thereare three open streams with constant pointers declared in the<stdio.h> header and associated with the standard open files.
At program start-up, three streams shall be predefined and need not be opened explicitly: standard input (for reading conventional input), standard output (for writing conventional output), and standard error(for writing diagnosticoutput). When opened, the standard error streamis not fully buffered; the standard input and standard output streamsare fully buffered if and only if the stream can be determined not torefer to an interactive device.
[sup][CX][/sup] The following symbolic values in <unistd.h> define the file descriptors that shall be associated with the C-language stdin, stdout, and stderr when the application is started:
STDIN_FILENOStandard input value, stdin. Its value is 0.STDOUT_FILENOStandard output value, stdout. Its value is 1.STDERR_FILENOStandard error value, stderr. Its value is 2.The stderr stream is expected to be open for reading and writing.


RETURN VALUE
[blockquote]None.
[/blockquote]ERRORS
No errors are defined.
作者: beyes    时间: 2008-11-16 23:08
通常,每个 Unix 程序在启动时都会打开三个流,一个用于输入,一个用于输出,一个用于打印诊断或错误消息。典型的,他们被连接到用户的终端但是也有可能指向文件或是其他设备,取决于父进程选择设置了什么。

       输入流被称为 ``standard input''; 输出流被称为 ``standard output''; 错误流输入流被称为 ``standard error'';这些名词通常简写为符号,用于引用这些文件,它们是 stdin, stdout, 和 stderr.

    这些符号中,每一个都是 stdio 中的一个宏,类型是指向 FILE 的指针,可以用于类似 fprintf 或 fread 等函数中。
 
   
   由于符号 stdin, stdout, 和 stderr 被指定为宏,为它们赋值将导致不可移植。

    错误流 stderr 是非缓冲的。输出流 stdout 是行缓冲的,如果它指向一个终端。




欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2