Skip to content
← Back to Community
C++ How get press any key to continue
Profile icon
PaulAdams4

In repel it C++ how do you program press any key to continue? The best I've come up with is cin.get(). This works fine until I try to embed them in If statements. I'm trying to make a text game. When the user goes to the next turn, I need the program to test a bunch of If conditionals. If the condition fires off the player is presented with text updating them on the circumstances happening. I need a way to stall the text so the player can read the text and then hit enter to continue. Cin.get() works fine outside of If statements. But, I've noticed its stalls even when a condition in an If statement is not met. Whats the best way to do press any key to continue?

Voters
Profile icon
ScaredPottah
Profile icon
PaulAdams4
Comments
hotnewtop
Profile icon
Highwayman

This is probably one of the longest threads on that very topic you will ever see.
http://cplusplus.com/forum/beginner/1988/

Profile icon
Highwayman

@Highwayman
also, short answer:

#include <iostream> int main() { std::cout << "Press Enter to continue" << std::endl; std::cin.ignore(1000000000, '\n'); return 0; }