How to hide System ("PAUSE")

zhaozj2021-02-16  53

People who have used DEV-C must know that to stop the output screen, must add a statement like System ("Pause" or cin.get () in the main body. Let's take advantage of some of the characteristics of C and standard library functions, how to hide System ("Pause"). / * Pause.h * / # include #include #ifndef __CPAUSE __ # define __CPAUSE__class CPause {static void system () {std :: system ( "pause");} public: CPause () {std: : atExit (& CPAUSE :: System);}} m_pause _; # ENDIF / / __ CPAUSE__ where Atexit is the specified function runs at the end of the program, M_PAUSE_ is an instance of CPAUSE. Its constructor will execute before the main () master function, actually using this feature of the global object. Operation example: / * example.cpp * / # include #include "pause.h" // Now define the PAUSE header file, you can stop the output screen .using namespace std; int main () {cout << "Hello, World" << Endl; Return (0);

转载请注明原文地址:https://www.9cbs.com/read-26550.html

New Post(0)