Visual C++ 启用控制台 [英] Visual C++ Enable Console

查看:25
本文介绍了Visual C++ 启用控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual C++ 中创建了一个空项目,但现在我需要控制台来显示调试输出.

I created an Empty Project in Visual C++, but now I need the Console to display debug output.

如何在不重新创建项目或在 VS 输出窗口中显示输出的情况下启用控制台?

How can I enable the Console without recreating the project or show the output in the VS output window?

推荐答案

你可以随时调用AllocConsole 在代码中为您的应用程序创建一个控制台,并将其附加到进程.FreeConsole 将删除控制台,将进程从它也是.

You can always call AllocConsole in code to create a console for your application, and attach it to the process. FreeConsole will remove the console, detaching the process from it, as well.

如果您希望所有标准输出流数据都进入控制台,您还需要使用 SetStdHandle 来适当地重定向输出.这是一个页面显示完成这个完整过程的工作代码,包括分配控制台并重定向输出.

If you want all standard output stream data to go to the console, you need to also use SetStdHandle to redirect the output appropriately. Here is a page showing working code to do this full process, including allocating the console and redirecting the output.

这篇关于Visual C++ 启用控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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