Re: Iterator
On Feb 19, 8:35 pm, "Fraser Ross" <z...@z.com> wrote:
typedef std::basic_ifstream<char> Stream;
Stream fileStream;
try {
fileStream.open(Name().c_str(), std::ios_base::binary);
if (fileStream.is_open()) {
typedef std::istream_iterator<ColourType, Stream::char_type> Iter;
bool const test2(Iter() == Iter(fileStream));
Why is test2 set to true? The file being read is ok. ColorType is a 32
bit integer.
The istream_iterators read ahead. (They have to, in order to
know when end of file is reached *before* they are
dereferenced.) You haven't told us what the file contains, but
the istream_iterators use << to read: a formatted input
function. If the data in the input stream is not formatted
correctly---for an integer, this means that the next non white
space is a digit or a sign followed by a digit, the input fails,
which terminates the iteration.
After the end of the iteration, it might be useful to check why
the iteration terminated: if !fileStream.eof(), it was due to
a format error (or some hardware failure, if fileStream.bad()).
--
James Kanze