曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 5433|回复: 1
打印 上一主题 下一主题

stderr, stdin, stdout - standard I/O streams

[复制链接]

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34395
跳转到指定楼层
楼主
发表于 2008-11-16 23:08:15 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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.

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34395
沙发
 楼主| 发表于 2008-11-16 23:08:30 | 只看该作者
通常,每个 Unix 程序在启动时都会打开三个流,一个用于输入,一个用于输出,一个用于打印诊断或错误消息。典型的,他们被连接到用户的终端但是也有可能指向文件或是其他设备,取决于父进程选择设置了什么。

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

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

    错误流 stderr 是非缓冲的。输出流 stdout 是行缓冲的,如果它指向一个终端。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2025-5-6 13:01 , Processed in 0.082915 second(s), 21 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表