Hi, I'm trying to get started with Visual C++ in Visual Studio 2008. When I press the play button (start debugging), a console opens, but then immediately closes. How do I make this window stay open so that I can see my output?
It's doing that because the program is ending. You can stop it from doing this by setting a breakpoint on the last statement of the program (this will cause it to stop and you can look at the program state in the debugger), or you can wait for a key input.
I prefer to set breakpoints as this gives you the opportunity to look at the program state.
You can set a breakpoint by right clicking on a line of code and selecting set breakpoint.
Edit: A breakpoint will only be hit when you're debugging, so if you want to make the application wait when you're not debugging you'll need to wait for some input from the user (i.e. "Press any key to continue")
To wait for a keypress just use the following:
system("pause");
You can also push Ctrl + F5 to start without debugging and it keeps the console open when your program ends.
By default, a Console Application will just close after completing for a debugging session. This is different than a normal run session where it will pause until you hit enter. You can get it to stop a few ways, but the easiest in to just set a break point on the closing brace of the main method.
Just put the cursor on the closing brace and hit F9. That should do the trick