Boost logo

Boost Users :

From: pktao_at_[hidden]
Date: 2006-08-01 18:49:01


Dear Boost users --I have a simple question about how to test for eof.

I usually use:

std::ifstream inputDataStream("path to file");

and test for EOF by: inputDataStream.eof()

I tried the same thing using:

boost::filesystem::basic_ifstream<char>
   inputDataStream("path to file", std::ios_base::in);

and test for EOF by: inputDataStream.eof() but its not working. Am I using the
.eof() correctly in the boost version of basic_ifstream?

Here is the broken code using the boost version of basic_ifstream:

int main() {

    boost::filesystem::path dataPath("/tao/data");

    if ( !exists(dataPath) ) {

        std::cerr << "Path does not exist!";

        return EXIT_FAILURE;

    };

    for (boost::filesystem::directory_iterator fileIterator(dataPath);

         fileIterator != boost::filesystem::directory_iterator();

         fileIterator++) {

             const boost::filesystem::path InputFileName = dataPath/fileIterator
-> leaf();

             boost::filesystem::basic_ifstream<char>
inputDataStream(InputFileName, std::ios_base::in);

             int i = 1;

             int previousIterator = 0;

             trialOnsetWrite();

             while ( !inputDataStream.eof() ) {

                 if ( (previousIterator + 3) == i) {

                     immobileWrite(i);

                     previousIterator = previousIterator + 3;

                 }

                 else {

                     dataStructureWrite(i);

                 };

                 i++;

             };

             trialOffsetWrite(i);

    };

    return (0);

};

Very appreciative,
Patrick


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