preventing an exe file from closing [duplicate]

喜欢而已 提交于 2019-12-28 07:03:11

问题


Possible Duplicate:
How to stop C++ console application from exiting immediately?

I created an exe file in c. When I run it command prompt opens and then closes quickly and I cannot see the output. The program takes no runtime values from users. It reads data from a file. Is there any way to prevent this?


回答1:


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




回答2:


One classic way to do it:

#include <stdio.h>

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

This will wait for keypress at the end.




回答3:


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");



回答4:


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




回答5:


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

int main() {
    ...
    ...
    system("pause");
}


来源:https://stackoverflow.com/questions/5148248/preventing-an-exe-file-from-closing

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