First off topic name is wrong, it's meant to be: ifstream resetting get pointer position
I'm having trouble resetting the get pointer position. I want to read a file, then set the get pointer back to the beginning of the file, so then if my function is called again it will re-read the entire file. The problem is it will only read it once, and for some reason it won't reset properly. Another thing, I'm getting odd output. It will paste everything in the file, then it will repeat the very last line once, this is an example output:
Say the file contains:
Code:
www.hi.com
www.hello.com
www.sup.com
The output will be like this:
Code:
www.hi.com
www.hello.com
www.sup.com
www.sup.com
It always repeats the last line for some odd reason that I cannot see. Ok here are the important bits of code to help diagnose the problem, thanks!:
Code:
class Crawl {
public:
Crawl();
void PrintMenu();
private:
ofstream writeStream;
ifstream readStream;
};
Crawl::Crawl() {
writeStream.open("crawler.txt", ios_base::app);
readStream.open("crawler.txt");
}
void Crawl::PrintCrawl() {
string x;
while (!readStream.eof()) {
readStream >> x;
cout << x << "\n";
}
readStream.seekg(0, ios_base::beg);
readStream.clear();
}