J
john
I am reading TC++PL3 and in "21.3.3 Stream State", 4 member functions
returning bool are mentioned:
template <class Ch, class Tr= char_traits<Ch> >
class basic_ios: public ios_base {
public:
// ...
bool good() const; // next operation might succeed
bool eof() const; // end of input seen
bool fail() const; // next operation will fail
bool bad() const; // stream is corrupted
[...]
};
It is also mentioned:
"If the state is good() the previous input operation succeeded. If the
state is good(), the next input operation might succeed; otherwise, it
will fail.
==> Applying an input operation to a stream that is not in the good()
state is a null operation as far as the variable being read into is
concerned."
Q1: What does the above mean?
==> "If we try to read into a variable v and the operation fails,"
Q2: Does this mean that fail() becomes true after this?
"the value of v should be unchanged (it is unchanged if v is a variable
of one of the types handled by istream or ostream member functions). The
difference between the states fail() and bad() is subtle. When the state
is fail() but not also bad(), it is assumed that the stream is
uncorrupted and that no characters have been lost. When the state is
bad(), all bets are off".
Q3: When !good() is true, is fail() always true?
returning bool are mentioned:
template <class Ch, class Tr= char_traits<Ch> >
class basic_ios: public ios_base {
public:
// ...
bool good() const; // next operation might succeed
bool eof() const; // end of input seen
bool fail() const; // next operation will fail
bool bad() const; // stream is corrupted
[...]
};
It is also mentioned:
"If the state is good() the previous input operation succeeded. If the
state is good(), the next input operation might succeed; otherwise, it
will fail.
==> Applying an input operation to a stream that is not in the good()
state is a null operation as far as the variable being read into is
concerned."
Q1: What does the above mean?
==> "If we try to read into a variable v and the operation fails,"
Q2: Does this mean that fail() becomes true after this?
"the value of v should be unchanged (it is unchanged if v is a variable
of one of the types handled by istream or ostream member functions). The
difference between the states fail() and bad() is subtle. When the state
is fail() but not also bad(), it is assumed that the stream is
uncorrupted and that no characters have been lost. When the state is
bad(), all bets are off".
Q3: When !good() is true, is fail() always true?