C++ wait for user input [duplicate]
What would be the best way to wait for user input in console application?
std::cout << "press any key to exit..."; // wait for user to hit enter or another key
Several ways to do so, here are some possible one-line approaches:
getchar()(expected for Enter, need
cin.get()(expected for Enter, need
PS: This method will also print
Press any key to continue . . .on the screen. (seems perfect choice for you :))
Edit: As discussed here, There is no completely portable solution for this. Question 19.1 of the comp.lang.c FAQ covers this in some depth, with solutions for Windows, Unix-like systems, and even MS-DOS and VMS.