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 200
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.
Bring "Start without debug" to the Debug menu...
Tools >> Customize >> Commands(Tab) >> Menu bar(drop down list) >> Debug(Controls Option) >> Add Command(button) >> Debug(Categories List) >> Start without debug
Using "Start without debug" Will allow VS2010 to display the "Press any key to continue" phrase before exiting.
If you want it to stay open, you need to add code to your program. Like it
#include <stdio.h>
#include <stdlib.h>
... main(...)
{
your codes
.
.
.
system("pause");
}
if you add this code ,your black screen stay at open. " system("pause") " inside the stdlib.h header file.
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.
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!
FWIW, the "Start Without Debugging" command works in VS2010 exactly the same way it does for me in previous Visual Studio versions (that is, for a console project the console remains open when the process terminates with a "Press any key to continue . . ." prompt).
So, exactly how are you getting VS2010 to run your program? If you're using the "Ctrl-F5" shortcut, can you verify that Ctrl-F5 is bound to Debug.StartWithoutDebugging
in "Options/Environment/Keyboard"?
Also, can you try running your program using the menu ("Debug/Start Without Debugging")?