Alex Vinokur wrote:
I tried to print
cout << "<" << infile.rdbuf() << ">" << endl;
while infile is empty.
Here is what I have got.
<
I expected to get
<>
What is wrong?
The inserter for stream buffers is a somewhat odd creature:
it has no option to set any state flags on the input stream
since the state flags are members of the stream classes not
of the stream buffers. Thus, it reports failure to insert
at least one character, resulting from not obtaining one
character from the stream buffer in the first place, by
setting 'failbit' on the output stream. This is standard
conforming behaivor. You should clear the flag after
insertion if you are not interested in it, e.g. with a simple
manipulator:
/**/ template <typename cT, typename Tr>
/**/ std::basic_ios<cT, Tr>& clear(std::basic_ios<cT, Tr>&s)
/**/ {
/**/ s.clear();
/**/ return s;
/**/ }
/**/ std::cout << "<" << in.rdbuf() << clear << ">\n";
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting