Assuming your question is "How do I resume input after the stream state has been set?" then there is a simple explanation:
The while
loop in which you performed the extraction terminated only until the extraction failed; this also includes when the stream reaches the end of the input stream (EOF). When that happens the eofbit will be set in the steam state (as well as the failbit). A stream can't be used for I/O when its stream state is set. In order to use it again, the stream state must be cleared. This is done using the member function clear(std::ios_base::iostate err = std::ios_base::goodbit)
.
std::cin.clear();
That call will clear the bits in the stream state and assign them to 0
(std::ios_base::goodbit
). After this call the stream can be used for I/O again.
This is assuming the stream read all the characters until it reached EOF. It's not sufficient for a pervious read that terminated upon the acquisition of invalid data. One would also have to ignore()
the remaining characters.
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');