zerkms
zerkms

Reputation: 255075

Rewind stream pointer to the line back

I have an input file stream and a string declared as:

std::ifstream finput;
std::string tmp_string;

and I read lines iteratively using std::getline(finput, tmp_string);

The question is: how to rewind the stream pointer so that after that rewind the second call of std::getline(finput, tmp_string); would return the same result (as one step before)?

Upvotes: 3

Views: 5186

Answers (1)

James Kanze
James Kanze

Reputation: 154027

Once you've read the line, it's too late. You can't go back to a position you haven't memorized. If you need this, the only solution is to call finput.gtell() before the getline, and then seek to what it returned.

Upvotes: 5

Related Questions