Press Enter to Continue

Viewed 108264

This doesn't work:

string temp;
cout << "Press Enter to Continue";
cin >> temp;
7 Answers
cout << "Press Enter to Continue";
cin.ignore();

or, better:

#include <limits>
cout << "Press Enter to Continue";
cin.ignore(std::numeric_limits<streamsize>::max(),'\n');

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.

Yet another solution, but for C. Requires Linux.

#include <stdio.h>
#include <stdlib.h>

int main(void) {
    printf("Press any key to continue...");
    system("/bin/stty raw"); //No Enter
    getchar();
    system("/bin/stty cooked"); //Yes Enter
    return 0;
}
Related