clear() resets the stream status flags. For example, when the stream
encounters an error (e.g. it wants to read an int and you give it
non-numeric characters), it sets a failure flag. Even after you skip over
the bad data with ignore() you can't continue reading until you reset the
flags with clear().
you shold first clear the error status,then ignore the bad data in the buffer.