When I type for example 7.3
|
The input operation takes characters from the stream and tries to construct an integer.
It can take the '7'. It cannot take '.', because no integer has a dot in it.
Since it already got at least one character before the '.' it can make an integer from the "7".
However, there are still ".3" in the input stream, waiting for next input operation.
If you would start by typing
.42
, then the first character in the stream would be the '.'
One cannot make a number from that. The
cin >> n;
would set the stream
cin
into state
fail and the .42 would still lurk there. Then you would have to first
cin.clear();
to reset the state before any read operation could succeed (and get rid of offending characters, if it is an int that you need to read).