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

Recommended Answers

All 3 Replies

Member Avatar for jencas

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

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

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)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.