How to stop console from closing on exit?

Visual StudioWindows 7

Visual Studio Problem Overview


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?

Visual Studio Solutions


Solution 1 - Visual Studio

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!

Solution 2 - Visual Studio

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

system("pause");

at the end of your program, then you'll get "Press any key to continue..." even when running in debug mode.

Solution 3 - Visual Studio

What about Console.Readline();?

Solution 4 - Visual Studio

Add a Console.ReadKey call to your program to force it to wait for you to press a key before exiting.

Solution 5 - Visual Studio

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:

  • in Visual Studio, right click your project in Solution Explorer or the tab with the file name if you have a file in the solution open, and choose Open Containing Folder or Open in Windows Explorer
  • in the resulting Windows Explorer window, double-click your way to the folder with the exe
  • Shift-right-click in the background of the explorer window and choose Open Commmand Window here
  • type the first letter of your executable and press tab until the full name appears
  • press enter

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsegfaultView Question on Stackoverflow
Solution 1 - Visual StudioSuhas BharadwajView Answer on Stackoverflow
Solution 2 - Visual StudiolapisView Answer on Stackoverflow
Solution 3 - Visual StudioRahul SoniView Answer on Stackoverflow
Solution 4 - Visual StudioSLaksView Answer on Stackoverflow
Solution 5 - Visual StudioKate GregoryView Answer on Stackoverflow