如何将输出重定向到屏幕后freopen函数(QUOT; out.txt"," A&QUOT ;,标准输出) [英] How to redirect the output back to the screen after freopen("out.txt", "a", stdout)
问题描述
#include <stdio.h>
int main() {
printf("This goes to screen\n");
freopen("out.txt", "a", stdout);
printf("This goes to out.txt");
freopen("/dev/stdout", "a", stdout);
printf("This should go to screen too, but doesn't\n");
return 0;
}
我打电话freopen函数重定向的标准输出的到out.txt然后我打印的文件的东西,现在我想将其重定向到屏幕,但则freopen(的/ dev /标准输出,一,标准输出); 的不起作用。有没有办法做到这一点使用ANSI C或POSIX系统调用?
I call freopen to redirect the stdout to out.txt then I print something on the file, now I want to redirect it back to the screen, but freopen("/dev/stdout", "a", stdout); doesn't work. Is there any way to do that using ANSI C or POSIX system calls?
推荐答案
我不能想办法在跨平台的方式做到这一点,但在GNU / Linux系统(也许其他POSIX兼容的人,太),你可以则freopen(为/ dev / tty的,一,标准输出)
。难道这是你想干什么?
I can't think of a way to do this in a cross-platform manner, but on GNU/Linux systems (and maybe other POSIX-compliant ones, too) you can freopen ("/dev/tty", "a", stdout)
. Is this what you were trying to do?
这篇关于如何将输出重定向到屏幕后freopen函数(QUOT; out.txt&QUOT;,&QUOT; A&QUOT ;,标准输出)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!