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

前端 未结 21 1695
灰色年华
灰色年华 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:07

    Just press CNTRL + F5 to open it in an external command line window (Visual Studio does not have control over it).

    If this doesn't work then add the following to the end of your code:

    Console.WriteLine("Press any key to exit...");
    Console.ReadKey();
    

    This wait for you to press a key to close the terminal window once the code has reached the end.

    If you want to do this in multiple places, put the above code in a method (e.g. private void Pause()) and call Pause() whenever a program reaches a possible end.

提交回复
热议问题