Chinaunix首页 | 论坛 | 博客
  • 博客访问: 61058
  • 博文数量: 26
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 255
  • 用 户 组: 普通用户
  • 注册时间: 2013-09-18 10:40
文章分类

全部博文(26)

文章存档

2013年(26)

我的朋友

分类: C/C++

2013-09-19 11:06:26

C语言中标准输入流、标准输出流、标准错误输
出流
在Linux中,所有对设备和文件的操作都使用文件描述符来进行。
Linux中一个进程启动时,都会打开3个文件:标准输入、标准输出和标准出错处理。这三个文件
分别对应文件描述符0、1、2。
在C语言中,在程序开始运行时,系统自动打开3个标准文件:标准输入、 标准输出、标准出错
输出。通常这3个文件都与终端相联系。因此,以前我们所用到的从终端输入或输出都不需要打开
终端文件。系统自定义了3个文件指针stdin、stdout、stderr,分别指向终端输入、终端输出和标准
出错输出(也从终端输出)。
标准输入流:stdin
标准输出流:stdout
标准错误输出流:stderr
FILE * stdin;

object
Standard input stream
The standard input stream is the default source of data for applications. It is usually directed to the
input device of the standard console (generally, a keyboard).
can be used as an argument for any function that expects an input stream as one of its
parameters, like fgets or fscanf.
stdin
Although it is generally safe to assume that the source of data for stdin is going to be a keyboard,
bear in mind that this may not be the case even in regular console systems, since stdin can be
redirected at the operating system level. For example, many systems, among them DOS/Windows
and most UNIX shells, support the following command syntax:
myapplication < example.txt
to use the content of the file example.txt as the primary source of data for myapplication instead
of the console keyboard.
It is also possible to redirect stdin to some other source of data from within a program using
the freopen function.
stdout
object

FILE * stdout;

object
Standard output stream
The standard output stream is the default destination of regular output for applications. It is usually
directed to the output device of the standard console (generally, the screen).
can be used as an argument for any function that expects an output stream as one of its
parameters, like fputs or fprintf.
stdout
Although it is generally safe to assume that the default destination for stdout is going to be the
screen, bear in mind that this may not be the case even in regular console systems,
since stdout can be redirected at the operating system level. For example, many systems, among
them DOS/Windows and most UNIX shells, support the following command syntax:
myapplication > example.txt
to redirect the output of myapplication to the file example.txt instead of the screen.
It is also possible to redirect stdout to some other source of data from within a program using
the freopen function.



阅读(1274) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:冒泡算法与最小选择法

给主人留下些什么吧!~~