Checkpoint 11.6.1.
- That token is skipped
- All of the numbers after 20 show up as 0
- There is an exception
12 34 and thinking of integers, it would make sense to call the tokens 12 and 34. But if we were looking at that same piece of text as some characters, we would think of it as the tokens 1, 2, ' ', 3, and 4.
>> operator says βskip past any whitespace, read one token, then stopβ. If it is trying to read into an integer, and encounters 10 20 it will read the number as 10 and then stop. The 20 is left for the next >>. If we use >> again at that point, it will read over the space at the start and then read the 20.
10 20 - but read into a char with >>, we would only get 1. The 0 20 would be left for future reads.
Numbers2.txt:
Data: Numbers2.txtNumbers.txt, but we will edit in just a minute. Because it has size integers separated by whitespace, we can simply >> into an integer variable 6 times to consume all the numbers. All of the spaces and even the newlines are automatically skipped over:
int variable?
>> on a stream that is in a failure state will not do anything - the variable being read into will get no new data and there will be no visible errors.
>> to see if there was an error and if so stop before trying to use that data:
x12? Do we read the 12? Skip it? There are almost an infinite number of things that could worry about. So most of the time, we wonβt try to βfixβ errors.
.clear() method to reset any error flags on the stream and
abc 123. We try to read in an integer. What do we get?
abc 123. We try to read in a string. What do we get?
abc 123. We try to read in a char. What do we get?