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

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

    Here is a way for C/C++:

    #include 
    
    #ifdef _WIN32
        #define WINPAUSE system("pause")
    #endif
    

    Put this at the top of your program, and IF it is on a Windows system (#ifdef _WIN32), then it will create a macro called WINPAUSE. Whenever you want your program to pause, call WINPAUSE; and it will pause the program, using the DOS command. For other systems like Unix/Linux, the console should not quit on program exit anyway.

提交回复
热议问题