如何在Visual Studio调试时进行输出重定向?

3
例如,如果我想从命令行执行此操作,我会使用"a.exe > out.txt"。在Visual Studio调试(F5)时是否可以做类似的事情?
3个回答

4
在项目属性中:
  • 输入命令行参数"> out.txt"
  • 禁用托管进程

1

只是确认一下,您不是在寻找使用以下内容在Visual Studio中输出的东西:

System.Diagnostics.Debug.WriteLine("this goes into the Output window");

对吗?


1

您可以在项目属性中使用“命令参数”进行重定向。

您还可以从程序中重定向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;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接