Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Best Practice for Combating the Console Closing Issue?

After compiling console programs the console window closes immediately after running. What is the best practice for keeping it open? I've searched google loads, I'm used to codeblocks where you don't have to worry about it, but, I want to mess around with Visual Studio a bit and with VS, my console closes. All over the interwebz there are several different ways to keep it open, however, I've read that most of them are bad coding techniques. What is everyones preferred method?

like image 898
Lonestar Avatar asked Jul 23 '09 17:07

Lonestar


3 Answers

When I'm using Visual Studio and I don't need debugging I just run it using Ctrl+F5 keystroke – and it prevents console from closing.

like image 64
Regent Avatar answered Nov 13 '22 21:11

Regent


Since you always run in the debugger, set a breakpoint on the return statement from main().

The debugger is your best friend, learn (and learn early) to use it to your advantage at every opportunity.

like image 25
Sam Harwell Avatar answered Nov 13 '22 20:11

Sam Harwell


Run your program in a console, which would be the expected way of running a console program ...

Alternatively, you can make a little batch file to execute your program that would have:

REM batch file to launch program
yourprogram.exe
PAUSE

and the PAUSE cmd.exe command will ask to user to press any key.

like image 21
erjiang Avatar answered Nov 13 '22 22:11

erjiang