Can I do several reading operations and then check fail() or do I need to
check fail() after every reading operation. Is it possible than a read
operation can set fail() and the next not? I am reading from a character
based stream in binary mode.
There is a big difference between "bad()", "fail()" and "good()". Bjarne
Stroustrup explains the stream state in his book:
(back translated from the german translation :-)
== snip
If good() or eof() is set, the previous input operations are a success.
If good() is set, the next input operation could by successful. If
good() isn't set, the next input operation will fail for sure. Each
input operation an a stream that isn't "good()" has no effect.
(...)
The difference between bad() and fail() is subtly. Is the state fail()
but not bad(), then it's possible that the stream is still usable and no
characters are lost. Is the stream state bad() the stream state is fully
undefined.
== endsnip
hope this will help
best regards
Tobias