I build the code, then when I try to run it, it executes and exits quickly . I am pretty sure that there is a way in the project configuration , but I forgot how . 开发者_如何学Python
You can always just use getc()
before the return. Enter a character and it will exit..
Or run the VS ctrl+f5
combination, or add a breakpoint if debugging.
Or you set a breakpoint on the last statement.
After a bit of googling, I found this solution that does not involve modifying your code. It contains a workaround that involves modifying your .vcxproj file.
To do this from within Microsoft Visual C++ 2010 Express (I'm assuming it is similar for Visual Studio 2010), open your project and navigate to the following menu: Project->$YOURPROJECTNAME Properties... ->Configuration Properties ->Linker ->System->SubSystem
Then use the dropdown to select Console (/SUBSYSTEM:CONSOLE) and apply the change.
"Start without debugging" should do the right thing now. Thanks All for your answers , but this works perfectly .
A way is to stick
system("PAUSE")
before the exit.
I must say the only time I used system("PAUSE") was at school when we were doing algorithm exercises. And I'm sre its bad pratice ^^
A cleaner way is to read the input like
scanf or cin
this way your program waits for a input in the keyboard
精彩评论