preventing an exe file from closing [duplicate]

三世轮回 提交于 2019-11-28 02:13:57

Run it natively from the command line.

Let's say that your file is in C:\awesomeness.exe

Open the cmd, type cd C:\ and then type awesomeness.exe

One classic way to do it:

#include <stdio.h>

int main() {
    puts("hai");
    getchar();
}

This will wait for keypress at the end.

Are you in Windows? If so, a quick and dirty way is to use the system() function in stdlib.h (make sure you include it) to execute the PAUSE command in the command prompt.

system("PAUSE");

If you are using Visual Studio, hit CTRL + F5 instead of F5 in order to run your program.

Using 'system("pause");' before ending main() is the most common method.

int main() {
    ...
    ...
    system("pause");
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!