如何将标准输出从Visual Studio重定向到输出窗口

编程入门 行业动态 更新时间:2024-10-17 19:29:16
本文介绍了如何将标准输出从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重定向到输出窗口

本文发布于:2023-07-06 07:38:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047396.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   重定向   窗口   标准   Visual

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!