Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Checking ifstream state

Reply
Thread Tools

Checking ifstream state

 
 
Fraser Ross
Guest
Posts: n/a
 
      06-18-2004
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.

Fraser.


 
Reply With Quote
 
 
 
 
Karl Heinz Buchegger
Guest
Posts: n/a
 
      06-18-2004
Fraser Ross wrote:
>
> 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?


No.
When a stream has gone into a fail state, it will refuse working until
you clear that fail state.
So once a read operation has failed all subsequent read operations will
also fail.

--
Karl Heinz Buchegger

 
Reply With Quote
 
 
 
 
Tobias Erbsland
Guest
Posts: n/a
 
      06-18-2004

> 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



 
Reply With Quote
 
Richard Herring
Guest
Posts: n/a
 
      06-18-2004
In message <>, Fraser Ross
<fraserATmembers.v21.co.unitedkingdom@?.?.invali d> writes
>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.
>

Once the fail state is set, it remains set until you clear it explicitly
by calling clear(). It's not even cleared by closing the file and
opening another, which often catches the unwary.

--
Richard Herring
 
Reply With Quote
 
Catalin Pitis
Guest
Posts: n/a
 
      06-18-2004
If I know correctly, there is also some exception support that can be
activated. In this case, you don't have to check the state after each
operation, but you can catch the exception in a try catch block...

Catalin

"Fraser Ross" <fraserATmembers.v21.co.unitedkingdom> wrote in message
news:...
> 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.
>
> Fraser.
>
>



 
Reply With Quote
 
Fraser Ross
Guest
Posts: n/a
 
      06-18-2004

"Tobias Erbsland"
> If good() or eof() is set, the previous input operations are a success.


Not necessarily. When extraction is done character-wise eof will be set
when an attempt is made to read past the last character and fail will be set
in conjunction.

Fraser.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
50th State checking in... TAP delivery wewa Windows 64bit 1 07-21-2005 01:52 PM
Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not permitted when session state mode is 'StateServer' or 'SQLServer'. Mike Larkin ASP .Net 1 05-23-2005 12:33 PM
What is the state of state machine after power-up without reset conditions Weng Tianxiang VHDL 7 11-25-2003 06:24 PM
unable to make the session state request to the session state server shamanthakamani ASP .Net 1 11-20-2003 04:51 AM
State machine: how to stay in a state? David Lamb VHDL 1 09-15-2003 05:24 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57