B
Bill Rudolph
The member function basic_ios:perator!() returns the bool result of
the basic_ios::fail() function which is true if either failbit or
badbit is set (This is per p. 616 of TC++PL by B. Stroustrup and p. 34
of Standard C++ IOStreams and Locales by Angelika Langer and Klaus
Kreft).
The implementation of the input stream iterator in the Langer and
Kreft book (see p. 129 to 130) uses the function:
void readElem()
{
if (istp!=0) if(!(*istp>>value)) istp=0;
}
in determining whether or not two istream iterators are equal as in
the following code:
vector<T> v(0);
ifstream f("input.txt");
copy(istream_iterator<T>(f),istream_iterator<T>(),back_inserter(v));
In this example, istream_iterator<T>(f) is equal to
istream_iterator<T>() if istp is equal to 0 for both iterators. istp
is set equal to 0 if the failbit or badbit is set--not if the eofbit
is set.
What happens when the end of file has been reached? Does the loop
continue until a failbit or badbit is set? Would the following code
(which reflects eofbit status) serve as an alternative?
void readElem()
{
istp!=0&&istp->good()?*istp>>value:istp=0;
}
the basic_ios::fail() function which is true if either failbit or
badbit is set (This is per p. 616 of TC++PL by B. Stroustrup and p. 34
of Standard C++ IOStreams and Locales by Angelika Langer and Klaus
Kreft).
The implementation of the input stream iterator in the Langer and
Kreft book (see p. 129 to 130) uses the function:
void readElem()
{
if (istp!=0) if(!(*istp>>value)) istp=0;
}
in determining whether or not two istream iterators are equal as in
the following code:
vector<T> v(0);
ifstream f("input.txt");
copy(istream_iterator<T>(f),istream_iterator<T>(),back_inserter(v));
In this example, istream_iterator<T>(f) is equal to
istream_iterator<T>() if istp is equal to 0 for both iterators. istp
is set equal to 0 if the failbit or badbit is set--not if the eofbit
is set.
What happens when the end of file has been reached? Does the loop
continue until a failbit or badbit is set? Would the following code
(which reflects eofbit status) serve as an alternative?
void readElem()
{
istp!=0&&istp->good()?*istp>>value:istp=0;
}