DEV Community

Discussion on: Interesting C++ bug involving `std::cin` for input.

Collapse
 
baenencalin profile image
Calin Baenen

How do you clear it?
The ignore method? (Or is that slightly different than what I want?

Collapse
 
_hs_ profile image
HS • Edited

I think that comment from @pgradot is the way to go. Check for failure, then clear the buffer, then ignore stuff, and finally do the rest - output messages and ask for inputs. Insted of clearing at the end as I suggested it's probably correct to first validate, clear, ignore.

So not just 'ignore' method but combination as described in mentioned comment links.