Hi,
For some reason, the following piece of code won't rewind the cursor position in the file stream:
The output is "EOF," not "Not EOF."Code:// C++ Statements std::ifstream FileStream; FileStream.open("MyFile"); char c; while(!FileStream.eof()) { FileStream.get(c); } FileStream.seekg(0, std::ios::beg); if(!FileStream.eof()) { std::cout << "Not EOF" << std::endl; } else { std::cout << "EOF" << std::endl; } // More C++ Statements
But the following piece of code does rewind the stream:
In this case, the output is "Not EOF."Code:// C++ Statements std::ifstream FileStream; FileStream.open("MyFile"); char c; while(!FileStream.eof()) { FileStream.get(c); } FileStream.close(); FileStream.open("MyFile"); if(!FileStream.eof()) { std::cout << "Not EOF" << std::endl; } else { std::cout << "EOF" << std::endl; } // More C++ Statements
Can someone please tell me why the seekg() statement is not rewinding the stream position?
Thanks in advance for your help.
*****
I am using g++ in FC5.



LinkBack URL
About LinkBacks


