Hi,

I wish to read the file twice. I am using ifstream to read the file. I tried using rewind(File pointer). But i get an error. How can i do it.

Thanks

The other option would be to close the file stream and then re-open, btw be sure to check that you actually need to read the file stream twice, rather than loading it contence into some data structure then reading that again. Just pointing that out because file access is slow in comparison.

Chris

The other option would be to close the file stream and then re-open, btw be sure to check that you actually need to read the file stream twice, rather than loading it contence into some data structure then reading that again. Just pointing that out because file access is slow in comparison.

Chris

Closing the file and opening it again in some compilers isnt pointing back to the beginning of the file.

However the second method which Chris said is quiet efficient.

Don't forget to clear file state if eof was reached:

... read file until eof
    // Now f is in fail() and eof(0 state...
    f.clear(); // Now f is capable to seek...
    f.seekg(0);
... read again ...
This question has already been answered. Start a new discussion instead.