Chapter 3. Input, output, and parsing

Streams have limited putback ability

From a news post:

Does anyone know if it is possible to put a line back onto the stream once it is read off?? We used istream and tried the putback function but that can only be passed characters. Do any of the other streams carry a function like this so that we can but line back on the stream as desired??

I don't think streams are powerful enough to do what you want. This is case when what you need is just a simple wrapper class. See the section called Don't be afraid to write small classes in Chapter 1.

Consider writing a buffer class of some kind which reads from a stream when you ask for more data than it has, but which allows you to put stuff back after reading it. To implement it, you might consider using a deque of chars. (double ended queue, look in STL under queue.)