Next: , Up: Unreading   [Contents][Index]


12.10.1 What Unreading Means

Here is a pictorial explanation of unreading. Suppose you have a stream reading a file that contains just six characters, the letters ‘foobar’. Suppose you have read three characters so far. The situation looks like this:

f  o  o  b  a  r
	 ^

so the next input character will be ‘b’.

If instead of reading ‘b’ you unread the letter ‘o’, you get a situation like this:

f  o  o  b  a  r
	 |
      o--
      ^

so that the next input characters will be ‘o’ and ‘b’.

If you unread ‘9’ instead of ‘o’, you get this situation:

f  o  o  b  a  r
	 |
      9--
      ^

so that the next input characters will be ‘9’ and ‘b’.