如何阻止控制台在退出时关闭?
我正在使用 Visual Studio 2010 和 Windows 7 x64
命令提示符在退出后关闭,即使我使用了“启动而不调试”。有我可以使用的设置吗?
I'm using Visual Studio 2010 and Windows 7 x64
The command prompt closes after exit, even though I used "Start without debug". Is there a setting somewhere that I can use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您只需按 Ctrl+F5 而不是 F5 即可运行构建的代码。然后它会提示您按任意键继续。或者你可以使用这一行 ->
system("pause");
在代码末尾,使其等待,直到您按下任意键。但是,如果您使用上面的行
system("pause");
并按 Ctrl+F5 运行,它会提示您两次!You can simply press Ctrl+F5 instead of F5 to run the built code. Then it will prompt you to press any key to continue. Or you can use this line ->
system("pause");
at the end of the code to make it wait until you press any key.However, if you use the above line,
system("pause");
and press Ctrl+F5 to run, it will prompt you twice!是的,在 VS2010 中他们以某种方式改变了这种行为。
打开您的项目并导航到以下菜单:项目 ->您的项目名称属性 ->配置属性->链接器->系统。在子系统字段中,使用下拉列表选择控制台 (/SUBSYSTEM:CONSOLE) 并应用更改。
“无需调试即可启动”现在应该做正确的事情。
或者,如果您用 C++ 或 C 编写,放在
程序末尾,那么即使在调试模式下运行,您也会得到“按任意键继续...”。
Yes, in VS2010 they changed this behavior somewhy.
Open your project and navigate to the following menu: Project -> YourProjectName Properties -> Configuration Properties -> Linker -> System. There in the field SubSystem use the drop-down to select Console (/SUBSYSTEM:CONSOLE) and apply the change.
"Start without debugging" should do the right thing now.
Or, if you write in C++ or in C, put
at the end of your program, then you'll get "Press any key to continue..." even when running in debug mode.
Console.Readline();
怎么样?What about
Console.Readline();
?向您的程序添加一个
Console.ReadKey
调用,以强制它在退出之前等待您按下某个键。Add a
Console.ReadKey
call to your program to force it to wait for you to press a key before exiting.您可以打开命令提示符,CD 到“调试”或“发布”文件夹,然后键入 exe 的名称。当我向人们建议这一点时,他们认为这是一项繁重的工作,但以下是最少的点击和击键:
我认为这是 14 次击键和单击(例如,将 Shift-右键单击算作两次),这确实不多。当然,一旦出现命令提示符,再次运行它只需向上箭头,然后输入即可。
You could open a command prompt, CD to the Debug or Release folder, and type the name of your exe. When I suggest this to people they think it is a lot of work, but here are the bare minimum clicks and keystrokes for this:
I think that's 14 keystrokes and clicks (counting shift-right-click as two for example) which really isn't much. Once you have the command prompt, of course, running it again is just up-arrow, enter.