如何在 Visual C++ 中保持控制台窗口打开? [英] How to keep the console window open in Visual C++?
问题描述
我刚开始使用 Visual C++,我想知道如何保留控制台窗口.
I'm starting out in Visual C++ and I'd like to know how to keep the console window.
例如,这将是一个典型的hello world"应用程序:
For instance this would be a typical "hello world" application:
int _tmain(int argc, _TCHAR* argv[])
{
cout << "Hello World";
return 0;
}
我遗漏了哪一行?
推荐答案
使用 Ctrl+F5 而不是 F5 启动项目.
Start the project with Ctrl+F5 instead of just F5.
控制台窗口现在将保持打开状态,并显示 Press any key to continue ...
程序退出后的消息.
The console window will now stay open with the Press any key to continue . . .
message after the program exits.
请注意,这需要 Console (/SUBSYSTEM:CONSOLE)
链接器选项,您可以按如下方式启用:
Note that this requires the Console (/SUBSYSTEM:CONSOLE)
linker option, which you can enable as follows:
- 打开您的项目,然后转到解决方案资源管理器.如果你在 K&R 跟随我,你的解决方案"将是你好",下面有 1 个项目,你好"也是粗体.
- 右键单击你好"(或任何您的项目名称.)
- 选择属性"从上下文菜单中.
- 选择配置属性>链接器>系统.
- 对于子系统"右侧窗格中的属性,点击右侧栏中的下拉框.
- 选择控制台 (/SUBSYSTEM:CONSOLE)"
- 点击应用,等待它完成它所做的一切,然后点击确定.(如果应用"显示为灰色,请选择其他子系统选项,单击应用",然后返回并应用控制台选项.我的经验是确定"本身不起作用.)
CTRL-F5 和子系统提示一起工作;它们不是单独的选项.
CTRL-F5 and the subsystem hints work together; they are not separate options.
(由 DJMorreTX 提供,来自 http://social.msdn.microsoft.com/Forums/en-US/vcprerelease/thread/21073093-516c-49d2-81c7-d960f6dc2ac6)
(Courtesy of DJMorreTX from http://social.msdn.microsoft.com/Forums/en-US/vcprerelease/thread/21073093-516c-49d2-81c7-d960f6dc2ac6)
这篇关于如何在 Visual C++ 中保持控制台窗口打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!