0

Hi I got a code that in pseudo dos something like

ifstream os;
while(os.oef()){
   os.getline(buffer,length);
}

If some condition is met,
I'd like to be able to jump back to the previous line,
such that the next getline will give the line just-read in, at a later time in my execution timeline.

Is this possible?

thanks

4
Contributors
3
Replies
5
Views
8 Years
Discussion Span
Last Post by mvmalderen
1

Use two buffers or even better two std::strings:

ifstream os; // variable name misleading!
string prev, curr;
while(getline(os, curr))
{
   ...
   prev = curr;
}
Votes + Comments
Good advice, simple and clever :)
0

To the OP:
Don't write your code like this: while(os.eof()) , instead write it like jencas did.
Want to know why? Do a forum search on: feof or eof :)

Edit:: I thought it was safely to assume that the 'oef' in 'os.oef()' is a typo he made.
(Because AFAIK there is no such data member in the iostream class library)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.