When using functions such as gets to input string, we normally use fflush(stdin) to Clear input buffer for next input.
But when using cin.getline, how to KeyFlush?
TIA
Nima
Printable View
When using functions such as gets to input string, we normally use fflush(stdin) to Clear input buffer for next input.
But when using cin.getline, how to KeyFlush?
TIA
Nima
>we normally use fflush(stdin) to Clear input buffer for next input
which is undefined. You can use something like -
cin.ignore(80,'\n');
That wont always work. The reason being that any operation on a failed stream is destined to fail. If the stream has its failbit set due to a string being entered when an int was expected for example you will have to call cin.clear() before cin.ignore() to ensure that the ignore operation succeeds.Quote:
You can use something like - cin.ignore(80,'\n');