This question already has an answer here:
I'm using Visual Studio 2010 and Windows 7 x64
The command prompt closes after exit, even though I used "Start without debug". Is there a setting somewhere that I can use?
This question already has an answer here:
I'm using Visual Studio 2010 and Windows 7 x64
The command prompt closes after exit, even though I used "Start without debug". Is there a setting somewhere that I can use?
You can simply press Ctrl+F5 instead of F5 to run the built code. Then it will prompt you to press any key to continue. Or you can use this line ->
system("pause");
at the end of the code to make it wait until you press any key.However, if you use the above line,
system("pause");
and press Ctrl+F5 to run, it will prompt you twice!You could open a command prompt, CD to the Debug or Release folder, and type the name of your exe. When I suggest this to people they think it is a lot of work, but here are the bare minimum clicks and keystrokes for this:
I think that's 14 keystrokes and clicks (counting shift-right-click as two for example) which really isn't much. Once you have the command prompt, of course, running it again is just up-arrow, enter.
Add a
Console.ReadKey
call to your program to force it to wait for you to press a key before exiting.Yes, in VS2010 they changed this behavior somewhy.
Open your project and navigate to the following menu: Project -> YourProjectName Properties -> Configuration Properties -> Linker -> System. There in the field SubSystem use the drop-down to select Console (/SUBSYSTEM:CONSOLE) and apply the change.
"Start without debugging" should do the right thing now.
Or, if you write in C++ or in C, put
at the end of your program, then you'll get "Press any key to continue..." even when running in debug mode.
What about
Console.Readline();
?