ok i think i made some understanding.

Code:
cin.ignore(numeric_limits<int>::max(), '\n');
When cin takes in an inproper format, it sets failbit and the input still remains in the buffer stream. After we set it back to good state, we have to discard the inproper input. But how do we know how many characters to discard?