Press Enter to Continue


Question

This doesn't work:

string temp;
cout << "Press Enter to Continue";
cin >> temp;
1
35
6/6/2015 11:40:25 PM

Accepted Answer

cout << "Press Enter to Continue";
cin.ignore();

or, better:

#include <limits>
cout << "Press Enter to Continue";
cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
74
7/15/2018 9:42:28 PM

Try:

char temp;
cin.get(temp);

or, better yet:

char temp = 'x';
while (temp != '\n')
    cin.get(temp);

I think the string input will wait until you enter real characters, not just a newline.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon