Newsgroups: comp.lang.c++ Path: utzoo!censor!geac!alias!rae From: rae@alias.com (Reid Ellis) Subject: Re: istream problem Message-ID: <1991May25.174532.15632@alias.com> Sender: news@alias.com (0000-news(0000)) Organization: Alias Research, Inc., Toronto ON Canada References: <1991May23.181402.7912@milton.u.washington.edu> Distribution: usa Date: Sat, 25 May 1991 17:45:32 GMT Michael Kenney writes: | func(istream &in) | { | . | . | . | while(in.get(c)) | { | // Do something | } | | in.seekg(0, ios::beg); | | // This loop FAILS | while(in.get(c)) | { | // Do something else | } | } | |The problem is, the second while loop never iterates, in.get() returns |0. I used in.tellg() to insure that the stream is repositioned, and it |is. Am I missing something obvious? Well, you *are* missing something, but no, it isn't obvious [which is why I'm posting]. I discovered this when I derived a couple of classes from fstream and streambuf. The problem is that ios [from which both istream and ostream are derived] maintains a state within itself, WHICH IS NOT RESET WHEN YOU 'REWIND' THE STREAM. It took me a few hours to figure this one out. So, all you have to do is reset the error state of the stream, by saying "in.clear();" after you hit EOF. I don't think it matters if you call clear() before or after the seekg(). Hope this helps other people bitten by the same thing. I'm still of two minds about whether istream::seekg() [and ostream::seekp() for that matter] should reset the ios::eofbit bit of the error state.. Reid -- Reid Ellis rae@utcs.toronto.edu || rae@alias.com CDA0610@applelink.apple.com || +1 416 362 9181 [work]