. Advertisement .
..3..
. Advertisement .
..4..
How to press any key to continue in C++? Below is my code
std::cout << "press any key to exit...";
// wait for user to hit enter or another key
Please give me a few practical suggestions.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are several ways to do:
getch()
(need#include <conio.h>
).getchar()
(expected for Enter, need#include <iostream>
).cin.get()
(expected for Enter, need#include <iostream>
).system("pause")
(need#include <iostream>
, Windows only).Press any key to continue . . .
will also be printed on the screen.A do while loop is a great way to wait for user input. This is how it looks:
The function
system('PAUSE')
can also be used, but this is slower and more platform-dependent.