Preventing console window from closing on Visual Studio C/C++ Console application

前端 未结 21 1655
灰色年华
灰色年华 2020-11-21 23:42

This is a probably an embarasing question as no doubt the answer is blindingly obvious.

I\'ve used Visual Studio for years, but this is the first time I\'ve done any

相关标签:
21条回答
  • 2020-11-21 23:55

    Visual Studio 2015, with imports. Because I hate when code examples don't give the needed imports.

    #include <iostream>;
    
    int main()
    {
        getchar();
        return 0;
    }
    
    0 讨论(0)
  • 2020-11-21 23:56

    You can also use this option

    #include <conio.h> 
    /* run this program using the console pauser or add your own getch, system("pause") or input loop */
    int main() {
       .
       .
       .
       getch(); 
    
       return 0;
    }
    
    0 讨论(0)
  • 2020-11-22 00:00

    If you run without debugging (Ctrl+F5) then by default it prompts your to press return to close the window. If you want to use the debugger, you should put a breakpoint on the last line.

    0 讨论(0)
  • 2020-11-22 00:00

    Right click on your project

    Properties > Configuration Properties > Linker > System

    Select Console (/SUBSYSTEM:CONSOLE) in SubSystem option or you can just type Console in the text field!

    Now try it...it should work

    0 讨论(0)
  • 2020-11-22 00:00

    Goto Debug Menu->Press StartWithoutDebugging

    0 讨论(0)
  • 2020-11-22 00:02

    In my case, i experienced this when i created an Empty C++ project on VS 2017 community edition. You will need to set the Subsystem to "Console (/SUBSYSTEM:CONSOLE)" under Configuration Properties.

    1. Go to "View" then select "Property Manager"
    2. Right click on the project/solution and select "Property". This opens a Test property page
    3. Navigate to the linker then select "System"
    4. Click on "SubSystem" and a drop down appears
    5. Choose "Console (/SUBSYSTEM:CONSOLE)"
    6. Apply and save
    7. The next time you run your code with "CTRL +F5", you should see the output.
    0 讨论(0)
提交回复
热议问题