-
waiting for <RETURN>
Hi I'm coding a program to run under the console (UNIX) and need a way to hold the screen until the user hit's the <RETURN> key before proceeding. I have usually achieved this in other languages by just having a temp read in statement and it works fine but under C++ it behave differently.
This is the function I made:
Code:
void waitForReturnKey()
{
char temp;
cout << "Press <RETURN> to continue..." << endl;
cin >> temp;
}
But this requires the user to type a char, but all I want is the user to hit return without typing anything. Also the problem with this is that is the user enters more than 1 char then a bug occurs.
-
Try:
Code:
char temp;
cin.get(temp);
That will get the next character entered and then move on. So you'd need to have that in a loop to get return:
Code:
char temp = 'a';
while(temp != '\n')
cin.get(temp);
...or something :)