Gang's Tech Stuff

Wait for ENTER key in C++

Posted by: Gangadhar on: May 3, 2011

There might be some instances where you want to wait for the ENTER key from the user. And with a constraint stating ‘not to use’ any non-standard libraries. I faced this situation a while ago and found out a simple solution stated below:


std::cout << “Press ENTER to continue…”;
std::cin.ignore( std::numeric_limits::max(), ‘\n’ );

Readers are kindly requested to share the different ways to achieve this task if they know!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.