clearing cin input? cin.ignore not a good way?
Posted
by igor
on Stack Overflow
See other posts from Stack Overflow
or by igor
Published on 2010-04-04T03:13:10Z
Indexed on
2010/04/04
3:23 UTC
Read the original article
Hit count: 287
What's a better way to clear cin input? I thought cin.clear and cin.ignore was a good way...?
code:
void clearInput()
{
cin.clear();
cin.ignore(1000,'\n');
//cin.ignore( std::numeric_limits<streamsize>::max(), '\n' );
}
My teacher gave me this reply...
this is basically saying that your clearInput doesn't work FYI: ignore is NEVER a good idea as a way of getting rid of all that remains on a line
and your failing this test is exactly the reason why now go clear it the correct way
© Stack Overflow or respective owner