I-O stream clearing question.


R. Clayton (rclayton@monmouth.edu)
(no date)


  I remember (or thought I remember) you saying that once your stream comes
  across an error (such that str.fail() or .bad() or .eof() is true), the only
  way to clear the stream status is to delete the descriptor.

If I said that I was telling you wrong. There are several ways to clear stream
state; the one I mentioned in class is to use the .clear() member function. I
may have mentioned that closing and re-opening a stream does not clear the
stream state. In particular, if you read to eof, close the stream, then
re-open the stream, the stream's eof bit is still set.

I did mention that the stream destructor closes the file associated with the
stream, but I also suggested that you explicitly call the .close() member
function rather than rely on the stream destructor.

  In my notes, (written in some form of chicken English), I wrote "stream
  state is sticky -- you (or it) can absolutely not clear the state"

That's why I provide attractively formatted and highly legible lecture notes.
The one for stream io
(http://bluehawk.monmouth.edu/rclayton/web-pages/s04-509/sio.html)
points out that "Stream state is sticky; once set, it stays set until
clear()ed."

  However, Koenig & Moo page 313 shows a .clear() which attempts to clear out
  the status??

Page 313 describes clear() and state predicates; page 57-58 shows and explains
clear() in use.

  So, if I'm writing a file and the disk is full, I may be able to do a { clear
  state; try writing again; if state==bad, wait a bit and try again} ?

You could, but it would be important for you to realize that what you're doing
is busy-waiting for disk space, which may or may not be an appropriate way to
handle full disks.



This archive was generated by hypermail 2.0b3 on Mon May 03 2004 - 17:00:06 EDT