Visual studio 2010 exiting after program ends

前端 未结 8 652
甜味超标
甜味超标 2021-02-04 13:44

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

相关标签:
8条回答
  • 2021-02-04 14:20

    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.

    0 讨论(0)
  • 2021-02-04 14:21

    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.

    0 讨论(0)
  • 2021-02-04 14:26

    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.

    0 讨论(0)
  • 2021-02-04 14:31

    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.

    0 讨论(0)
  • 2021-02-04 14:34

    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!

    0 讨论(0)
  • 2021-02-04 14:34

    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")?

    0 讨论(0)
提交回复
热议问题