fprintf()中的 stderr fprintf(stderr,"Can't open it!\n");fprintf(stdout,"Can't open it!\n");printf("Can't open it!\n");这3句效果不是一样啊,有什么区别吗?

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/16 07:50:28
fprintf()中的stderrfprintf(stderr,"Can''topenit!\n");fprintf(stdout,"Can''topenit!\n");printf("Can''topen

fprintf()中的 stderr fprintf(stderr,"Can't open it!\n");fprintf(stdout,"Can't open it!\n");printf("Can't open it!\n");这3句效果不是一样啊,有什么区别吗?
fprintf()中的 stderr
fprintf(stderr,"Can't open it!\n");
fprintf(stdout,"Can't open it!\n");
printf("Can't open it!\n");
这3句效果不是一样啊,有什么区别吗?

fprintf()中的 stderr fprintf(stderr,"Can't open it!\n");fprintf(stdout,"Can't open it!\n");printf("Can't open it!\n");这3句效果不是一样啊,有什么区别吗?
有区别.
stdout -- 标准输出设备 (printf("..")) 同 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!