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

前端 未结 21 1656
灰色年华
灰色年华 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-22 00:17

    (/SUBSYSTEM:CONSOLE) did not worked for my vs2013 (I already had it).

    "run without debugging" is not an options, since I do not want to switch between debugging and seeing output.

    I ended with

    int main() {
      ...
    #if _DEBUG
      LOG_INFO("end, press key to close");
      getchar();
    #endif // _DEBUG
      return 0;
    }
    

    Solution used in qtcreator pre 2.6. Now while qt is growing, vs is going other way. As I remember, in vs2008 we did not need such tricks.

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

    If you're using .NET, put Console.ReadLine() before the end of the program.

    It will wait for <ENTER>.

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

    Either use:

    1. cin.get();

    or

    1. system("pause");

    Make sure to make either of them at the end of main() function and before the return statement.

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