标题: 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 程序在启动时都会打开三个流,一个用于输入,一个用于输出,一个用于打印诊断或错误消息。典型的,他们被连接到用户的终端但是也有可能指向文件或是其他设备,取决于父进程选择设置了什么。