在 Visual Studio 2005 输出窗口中捕获 cout?
我创建了一个 C++ 控制台应用程序,只想捕获 Visual Studio 2005 IDE 中输出窗口中的 cout/cerr 语句。 我确信这只是我缺少的一个设置。 有人能指出我正确的方向吗?
I created a C++ console app and just want to capture the cout/cerr statements in the Output Window within the Visual Studio 2005 IDE. I'm sure this is just a setting that I'm missing. Can anyone point me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
Ben 的答案和 Mike Dimmick 的答案的组合:您将实现一个最终调用 OutputDebugString 的stream_buf_。 也许有人已经这样做了? 看一下建议的两个 Boost 日志记录库。
A combination of ben's answer and Mike Dimmick's: you would be implementing a stream_buf_ that ends up calling OutputDebugString. Maybe someone has done this already? Take a look at the two proposed Boost logging libraries.
这是输出屏幕闪烁然后消失的情况吗? 如果是这样,您可以使用 cin 作为返回前的最后一条语句来保持它打开。
Is this a case of the output screen just flashing and then dissapearing? if so you can keep it open by using cin as your last statement before return.
另外,根据您的意图以及您使用的库,您可能需要使用 TRACE 宏 (MFC) 或 ATLTRACE (ATL)。
Also, depending on your intentions, and what libraries you are using, you may want to use the TRACE macro (MFC) or ATLTRACE (ATL).
你不能这样做。
如果要输出到调试器的输出窗口,请调用OutputDebugString。
我发现了“teestream”的这种实现,它允许一个输出进入多个流。 您可以实现一个将数据发送到 OutputDebugString 的流。
You can't do this.
If you want to output to the debugger's output window, call OutputDebugString.
I found this implementation of a 'teestream' which allows one output to go to multiple streams. You could implement a stream that sends data to OutputDebugString.
您可以像这样捕获 cout 的输出,例如:
将其神奇地放入 Visual Studio 2005 输出窗口中作为 Visual Studio 2005 插件开发人员的练习。 但是您可能可以将其重定向到其他地方,例如文件或自定义窗口,也许可以通过编写自定义streambuf类(另请参阅boost.iostream)。
You can capture the output of cout like this, for example:
Magicking it into the Visual Studio 2005 output window is left as an exercise to a Visual Studio 2005 plugin developer. But you could probably redirect it elsewhere, like a file or a custom window, perhaps by writing a custom streambuf class (see also boost.iostream).
我终于实现了这个,所以我想与您分享:
额外提示:如果您
在输出窗口中写入:然后双击它,那么 Visual Studio 将跳转到给定的位置文件第 10 行,并在状态栏中显示“消息”。 它非常很有用。
I've finally implemented this, so I want to share it with you:
BONUS TIP: If you write:
to the output window and then double-click on it, then Visual Studio will jump to the given file, line 10, and display the 'message' in status bar. It's very useful.
写入 std::ostringsteam 然后跟踪它。
Write to a std::ostringsteam and then TRACE that.