Boost logo

Boost Users :

From: Frank Birbacher (bloodymir.crap_at_[hidden])
Date: 2006-08-02 18:42:50


Hi!

pktao_at_[hidden] schrieb:
> while ( !inputDataStream.eof() ) {
>
> if ( (previousIterator + 3) == i) {
>
> immobileWrite(i);
>
> previousIterator = previousIterator + 3;
>
> }
>
> else {
>
> dataStructureWrite(i);
>
> };
>
> i++;
>
> };

I cannot see where data is read. Anyway:
 - first: Test for any error: "while(inputDataStream) {...}"
 - second: Test after read:
        int sum = 0, i;
        while(inputDataStream >> i) { sum +=i; }

When using istream_iterator<T>, then just test against an end interator:

std::for_each(istream_iterator<int>(inputDataStream),
istream_iterator<int>(), &foo);

All of the above is true for both boost::filesystem::basic_ifstream and
std::ifstream. It is true for any std::istream.

HTH, Frank


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net