Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!unixhub!ditka!zinn!nuucp From: mjv@objects.mv.com (Michael J. Vilot) Newsgroups: comp.lang.c++ Subject: RE: istream::putback(char c) Message-ID: <1272@zinn.MV.COM> Date: 10 Apr 91 11:42:06 GMT Sender: news@ditka.chicago.com (Pulitzer at ditka) Lines: 29 >From brunix!sdm >Newsgroups: comp.lang.c++ >Message-ID: <71302@brunix.UUCP> >Organization: Brown University Department of Computer Science > >Two questions: > > 1. Why am I limited to putting back the last character I removed? > There is no such limitation for ungetc in the standard C library. > > 2. Given that I am limited to putting back the last character I > read, why does putback take a parameter? 1. The limitation does indeed exist for C. The ANSI C library definition of ungetc() includes the following caution: "One character putback is guaranteed. If the ungetc function is called too many time on the same stream without an intervening read or file position on that stream, the operation may fail." 2. For much the same reason the ANSI C function takes an argument. This has the virtue (? ;-) of being 'consistent' with what a C programmer would expect, but I agree that the semantic restrictions on pushing back a character tend to make the argument somewhat superfluous. Mike