如何将标准输出从Visual Studio重定向到输出窗口 [英] How to redirect standard output to output window from Visual Studio

查看:507
本文介绍了如何将标准输出从Visual Studio重定向到输出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将标准输出从Visual Studio重定向到输出窗口?

Is it possible to redirect standard output to the output window from Visual Studio?

我在程序中使用了OutputDebugString,但是我使用了一些带有带有printf或cout的输出调试消息的库.

I use OutputDebugString in my program, but I use some libraries that have output debug messages with printf's or cout's.

推荐答案

直接标准输出重定向将不起作用,因为没有对应于OutputDebugString的句柄.但是,应该有一种方法:

Straightforward standard output redirection will not work, as there is no handle corresponding to OutputDebugString. However, there should be a way:

可以通过以下方式完成:将标准输出重定向到管道,然后创建一个线程,该线程将读取该管道并使用OutputDebugString打印从该管道读取的任何内容.

It could be done by redirecting standard output to a pipe, and then creating a thread which would read the pipe and print anything read from it using OutputDebugString.

注意:我很久以前就打算实现此功能,因为我面临的问题与您完全相同(某些库使用printf或fprintf(stderr ....).但是,我从未真正做到过.我总是结束对库的修改,因此我没有可行的实现,但我认为从原理上讲应该是可行的.

Note: I was contemplating for a long ago to implement this, as I am facing exactly the same problem as you do (some libraries using printf or fprintf(stderr....). However, I never really did this. I have always ended modifying the libraries instead, and therefore I do not have a working implementation, but I think it should be feasible in principle.

这篇关于如何将标准输出从Visual Studio重定向到输出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆