Is there anyway that the console window remains open after the program is completed and closed after 1 keystroke?

The command-line program always closes the window after it is completed. I know that you can use cin.get(); to wait for user input. Is there a way that the user could press any key (instead of typing something, and then press enter) to close the program? I do not want to use system("PAUSE") as it is Windows dependent and slow.

I want him to pause so that the user can see that he has completed successfully and other details. It will probably not be launched from an already open command prompt, and the executable will be double clicked to run.

+6
source share
2 answers

Yes. "system (" PAUSE ") is one way. A simple" getchar () "or" cin "should be absolutely equivalent :)

0
source

This is an option with the OS, not in C / C ++. He must control how the terminal opens and closes. Similarly, if you invoked a package or command line application.

It is too platform dependent to publish code or configuration here (mostly a console GUI application with onClose instruction in our IDE)

-1
source

Source: https://habr.com/ru/post/923715/


All Articles