可以将 std::cout 重定向到开箱即用的 Visual Studio 2010 C++ 中的输出视图吗?

Posted

技术标签:

【中文标题】可以将 std::cout 重定向到开箱即用的 Visual Studio 2010 C++ 中的输出视图吗?【英文标题】:Can std::cout be redirected to output view in Visual Studio 2010 C++ out-of-the-box? 【发布时间】:2011-12-13 02:08:49 【问题描述】:

我想知道这是否可以在最新版本的 VS 中通过一个简单的设置来完成,该设置会导致 VS 在 Eclipse IDE 中以等同于“ContextMenu”>run“a_Java_src_file_with_main”的方式运行。我在新的 W7 平台上使用 VS 2010 Pro 的试用版。即使是添加到从“空”模板生成的项目中的最小 helloworld cpp 源文件也会重定向到命令窗口。

3年前同样的问题:Capturing cout in Visual Studio 2005 output window? 9 个月前:How to redirect stdout to output window from visual studio

我知道使用 OutputDebugString(...) 并将流重定向到文件作为替代方案。Capture console output for debugging in VS?

【问题讨论】:

How to redirect stdout to output window from visual studio的可能重复 Redirect Console.Write... Methods to Visual Studio's Output Window While Debugging的可能重复 【参考方案1】:

执行此操作的简单方法是通过使用WinMain entry point on windows instead of main 构建可执行文件来“suppress the console window”。

这通常可以通过编辑项目设置来完成,但是如果你像我一样使用cmake,那么每次调用cmake 构建时这些设置都会被覆盖。所以,在这种情况下你需要add WIN32 to executable target in CMakeList.txt or set CMAKE_WIN32_EXECUTABLE to true for cmake configure command。

【讨论】:

以上是关于可以将 std::cout 重定向到开箱即用的 Visual Studio 2010 C++ 中的输出视图吗?的主要内容,如果未能解决你的问题,请参考以下文章

开箱即用的移动应用同步服务

新注册用户将被重定向到密码重置屏幕

将标准输出重定向到文件[重复]

c ++将函数输出重定向到已编译的程序输入,反之亦然

任何 .NET ORM 是不是支持开箱即用的本地化实体?

ACDC:开箱即用的多租户数据集成平台