Visual C++ Enable Console(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++ 启用控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Visual C++ 启用控制台


基础教程推荐
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- CString 到 char* 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01