如何将程序的输出显示到文件和控制台(stdout)?(How to display the output of a program both to a file and to the console(stdout)?)
假设我有以下程序只输出“Hello World”:
//DEMO.c #include<stdio.h> int main() { printf("HELLO World"); }
现在我想将它显示在屏幕和文件
output.txt
。所以我在命令提示符下输入以下命令(我在Windows XP上使用CodeBlocks并将其配置为在命令提示符下工作):
demo.exe>>output.txt>>stdout
它不起作用! 请告诉我怎么做,即如何输出我在屏幕上看到的同样的东西(当我运行程序时),同时输出到文本文件?
Say I have the following program that simply outputs "Hello World":
//DEMO.c #include<stdio.h> int main() { printf("HELLO World"); }
Now I want to display it both to the screen and to a file
output.txt
.So I enter the following command in the command prompt(I use CodeBlocks on Windows XP and have configured it to work on command prompt as well):
demo.exe>>output.txt>>stdout
It doesn't work!!! Please tell me how to do it,ie how to output the same thing that I see on my screen(When i run the program),simultaneously to a text file?
原文:https://stackoverflow.com/questions/16165854