简体   繁体   English

在Visual Studio Express C ++中“按任意按钮继续”?

[英]“Press any button to continue” in Visual Studio Express C++?

创建控制台应用程序(空白文档)时,如何使“按任意按钮继续”自动显示?

You can add it manually with a system("pause"); 您可以使用system("pause");手动添加它system("pause");

*Be carefull, this is not portable (will work on windows, but might not work elsewhere) *请注意,这不是便携式的 (可在Windows上使用,但在其他地方可能无法使用)

When you run a console program in the IDE using "Start Without Debugging" ( Ctrl-F5 ) you get the behavior you're looking for. 当您使用“不调试开始”( Ctrl-F5 )在IDE中运行控制台程序时,您将获得所需的行为。

For some reason, when you start the program in the IDE under the debugger ("Start Debugging" or plain-old- F5 ) you don't get that prompt when the program ends. 出于某种原因,当您在IDE中的调试器下启动程序(“开始调试”或纯F5 )时,程序结束时不会出现该提示。 If you just want to be able to see the last bit of what's in the console window when run under the debugger, you can set a breakpoint on the return from main() (or the closing brace for main() ). 如果你只是希望能够看到什么在当调试器下运行控制台窗口中的最后一位,您可以在设置断点returnmain()或右括号的main()

There is no builtin function. 没有内置功能。 However you can do a simple loop with kbhit() and getch(), like so: 但是,您可以使用kbhit()和getch()进行一个简单的循环,如下所示:

#include <conio.h>

void main( void )
{
    // Display your message here

    for(;;)
    {
        while( !kbhit() );
        if (getch() == 0x0D)
            break; // Break on ENTER
    }

    // Continue on here
}

Adapted from http://support.microsoft.com/kb/44895 改编自http://support.microsoft.com/kb/44895

system("pause") is definitely what you were asking for, but using it is very bad practice. system(“ pause”)绝对是您所要的,但是使用它是非常不好的做法。 Consider just using cin.get() at the end and press enter. 考虑只在最后使用cin.get()并按Enter。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM