如何重定向stdout到输出窗口从visual studio [英] How to redirect stdout to output window from visual studio
问题描述
是否可以从Visual Studio将stdout重定向到输出窗口?我在我的程序OutputDebugString中使用,但我使用一些库输出具有printf或cout的调试消息。
Is it possible to redirect stdout to output window from Visual Studio? I use in my program OutputDebugString but I use some libraries that have output debug messages with printf's or cout's.
推荐答案
简单的stdout重定向不工作,因为没有句柄对应于OutputDebugString。但是,应该有一种方法:
Straightforward stdout redirection will not work, as there is no handle corresponding to OutputDebugString. However, there should be a way:
这可以通过将stdout重定向到管道,然后创建一个线程来读取管道并打印从它读取的任何东西使用OutputDebugString。
It could be done by redirecting the stdout to a pipe, 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, therefore I do not have a working implementation, but I think it should be feasible in principle.
这篇关于如何重定向stdout到输出窗口从visual studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!