您的位置:首页 > 编程语言 > C语言/C++

python以及c++中怎么把stdout恢复为标准输出

2011-04-01 20:19 363 查看
很多介绍怎么重定向到别的文件的,但好少定回来的。

其实很简单啊....内牛满面...

python中

sys.stdout = sys.__stdout__;

sys.stderr = sys.__stderr__;

c++中windows版为:

freopen( "CON", "w", stdout ); (参见链接http://support.microsoft.com/kb/58667/zh-cn

linux应该为

freopen( "/dev/tty", "w", stdout );

#include <stdio.h>
#include <stdlib.h>

void main(void)
{
FILE *stream ;
if((stream = freopen("file.txt", "w", stdout)) == NULL)
exit(-1);

printf("this is stdout output/n");

stream = freopen("CON", "w", stdout);

printf("And now back to the console once again/n");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐