I'm working on a simple program to analyse some data and I'm having trouble making multiple passes over my file. I've been trying to do something along the lines of

for(n=0;n<Nmax;n++){
                      while (! inFile.eof() ){
                            crap done here;
                      };   
    };

however it won't do more than one pass over the file. Is there a way I can make it pass over the file multiple times like this?

Recommended Answers

All 3 Replies

see,
after first pass of for look, file reading pointer will be at the end. so during next for loop passes it wont go inside while loop as (! inFile.eof() ) will be false.
You have to reset the file reading pointer to start of the file before while loop.

Ok, I got it working. I ended up inserting:

inFile.clear() ;
inFile.seekg( 0, std::ios::beg );

Thanks for the help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.