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.
相关文章