I am trying to find a way to replace pressing enter key in c++.
below is c code.
can someone help me?
after press enter key detected, user needs to provide some inputs to proceed further, which means that I need to allow the program in C++ to key in another inputs if an <enter key> is pressed
1 2 3 4 5 6
void PressEnter ()
{
printf("Press Enter to quit");
fflush(stdin);
getchar();
}
Unfortunately not with VS/Windows. Any existing chars in the input stream aren't removed before the prompt is displayed (which is what the if statement is attempting). So if existing input stream chars contain a '\n' char, then the .ignore() will return immediately.
What is needed is a cin.flush() function - but I don't know just using standard c++.
The issue is that even if there is cin data available, ->in_avail() returns 0 and ->sungetc() returns eof so the first .ignore() is not executed to remove existing input data before the prompt is displayed.