例如,如果我想从命令行执行此操作,我会使用"a.exe > out.txt"。在Visual Studio调试(F5)时是否可以做类似的事情?
只是确认一下,您不是在寻找使用以下内容在Visual Studio中输出的东西:
System.Diagnostics.Debug.WriteLine("this goes into the Output window");
对吗?
您可以在项目属性中使用“命令参数”进行重定向。
您还可以从程序中重定向stdout/err/in。在此处找到C++示例,唯一优点是比第一个更简单的解决方案具有可移植性。
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main ()
{
#ifdef _DEBUG
ofstream mout("stdout.txt");
cout.rdbuf(mout.rdbuf());
#endif
cout<< "hello" ;
return 0;
}