Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual studio 2010 exiting after program ends

I'm trying out Visual studio 2010 by compiling a C program. After it displays the solution in the "DOS" command window, the window is immediately closed. In Visual studio 2008, one gets the message press any key to continue and pressing a key closes the command prompt window. How do I set this behavior in 2010?

like image 403
yCalleecharan Avatar asked Apr 14 '10 18:04

yCalleecharan


Video Answer


3 Answers

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.

like image 83
vitavim Avatar answered Nov 02 '22 05:11

vitavim


The reason this happens is because now in VS 2010 it is possible to create an empty, generic C++ project by default, without having to go through the wizard. This causes VS 2010 to not properly set the Console (/SUBSYSTEM:CONSOLE) flag and so VS2010 has no idea it is a console application for which it would send the usual "Press any key..." prompt.

This problem doesn't occur if you create a Console Application project type from the New Project menu.

But then you can set this flag yourself and many others, through Project/Settings, as the above post has answered correctly!

like image 20
linnx88 Avatar answered Nov 02 '22 06:11

linnx88


This is normal. The "DOS" console window is attached to your program and is supposed to exit when your program finishes. If you want it to stay open, you need to add code to your program to keep it open. All you have to do is add a print statement and then input statement to the end of your program.

like image 42
Joel Coehoorn Avatar answered Nov 02 '22 05:11

Joel Coehoorn