stdout与stderr的区别

 

stdout是标准输出流,默认为屏幕,
stderr是标准错误流,一般把屏幕设为默认,  也可以输出到文件。 


两者默认向屏幕输出。
但如果用转向标准输出到磁盘文件,则可看出两者区别。stdout输出到磁盘文件,stderr在屏幕。

例如:
my.exe
Can't open it!
Can't open it!
Can't open it!

转向标准输出到磁盘文件tmp.txt
my.exe > tmp.txt
Can't open it!

用TYPE 看 tmp.txt的内容:
TYPE tmp.txt
Can't open it!
Can't open it!

[From: http://zhidao.baidu.com/link?url=KChwN-hf5yzWOJfJM3H9nENZq6Ba_QnDNdXX-_8-hNEHxBfjVv7PnuDTUvu55dUYuRbtd_avy4LY1dyuSlzU3a]

 

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

标准输入,输出应该是行缓冲
Line buffering is typically used on a stream when it refers to a terminal: standard input and standard output, for example.

摘自apue section 5.4

出错是无缓冲

举例来说就是你,printf(stdout, "xxxx"); 而不是printf(stdout, "xxxx\n"),前者会憋住,直到遇到新行才会一起输出
printf(stderr, "xxxxx"),不管有么有\n,都输出。

【From: http://bbs.chinaunix.net/thread-1634457-1-1.html】

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

 

你可能感兴趣的:(C++)