Please see below extract of code.
What I am trying to do is clear the keyboard buffer if the user enters a non numeric value.
Can I clear it all in one go?
Presumably if I can find how much data is in the buffer I can feed this into the first parameter of cin.ignore?
Is the buffer a fixed size. If so could set first parameter of cin.ignore to this. Not very elegant but should work.
Any suggestions greatly appreciated.
Regards
if (!cin.good())
{
cin.clear(); // clear fail bit
cin.ignore(1,'\n');
OptionSelected=10;
}
What I am trying to do is clear the keyboard buffer if the user enters a non numeric value.
Can I clear it all in one go?
Presumably if I can find how much data is in the buffer I can feed this into the first parameter of cin.ignore?
Is the buffer a fixed size. If so could set first parameter of cin.ignore to this. Not very elegant but should work.
Any suggestions greatly appreciated.
Regards
if (!cin.good())
{
cin.clear(); // clear fail bit
cin.ignore(1,'\n');
OptionSelected=10;
}