开发者

preventing an exe file from closing [duplicate]

This questio开发者_开发百科n already has answers here: Closed 11 years ago.

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?


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜