C++控制台应用程序运行控制台闪退

控制台闪退的主要原因是:代码运行完毕自动退出

解决方案:

  • system("PAUSE");   和system("pause");

    pause是DOS下的一个命令。简单的说就是暂停程序的执行,等待任意键继续执行。

  • std::cin.get();

    cin.get()暂停程序的执行,等待用户输入回车键,继续执行代码。

  •  死循环;   
while (1) {
        int key = _getch();
        if (key == 27) {
            //If Esc is pressed, exit the program.
            break;
        }
    }            

猜你喜欢

转载自www.cnblogs.com/foreversdf/p/12954507.html