Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: Problems with putback() Message-ID: <739@taumet.com> Date: 21 May 91 15:20:08 GMT References: <1991May20.213530.1864@jpl-devvax.jpl.nasa.gov> Organization: Taumetric Corporation, San Diego Lines: 33 russb@alexa.JPL.NASA.GOV (Russ Brill) writes: >I know there has been some discussion of istream::putback() over the >last month, but I didn't care much until now. We are getting failures >of this method (on Sun's cfront 2.0) at what appear to be rare and >random times. >Can you putback more than one character between extractions? Must the >argument match the extracted character(s)? Why might it otherwise >fail? You might not get more than one char of putback under certain circumstances depending on the details of the implementation. Putback bascically moves back the pointer in the input buffer. If the buffer were just filled, you might be limited to one character at that time. This would account for rare and random failures. Additionally, if the stream error state is not zero, putback will do nothing. If the input were unbuffered, you might be limited to one character of putback. The documentation for putback says that if the putback character does not match the one extracted, the effect is undefined. The reason for that is you might be reading a strstream from read-only storeage. When putback moves back the input pointer, it would not be possible to change what was pointed to. Under ordinary circumstances, you can putback anything, but you never know how much is safe to putback. Iostreams implement a general-purpose text I/O system, but not an all- purpose system. Some things cannot conveniently be done with the standard streams. You can extend the streams package to do other things, however. -- Steve Clamage, TauMetric Corp, steve@taumet.com