| | |
reread line using fstream getline
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2008
Posts: 149
Reputation:
Solved Threads: 8
Hi I got a code that in pseudo dos something like
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
C++ Syntax (Toggle Plain Text)
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
•
•
Join Date: Dec 2007
Posts: 360
Reputation:
Solved Threads: 69
Use two buffers or even better two std::strings:
C++ Syntax (Toggle Plain Text)
ifstream os; // variable name misleading! string prev, curr; while(getline(os, curr)) { ... prev = curr; }
Last edited by jencas; Jul 8th, 2009 at 8:04 am.
If you are forced to reinvent the wheel at least try to invent a better one!
Please use code tags - Please mark solved threads as solved
Please use code tags - Please mark solved threads as solved
To the OP:
Don't write your code like this:
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)
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)
Last edited by tux4life; Jul 8th, 2009 at 11:35 am.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
![]() |
Similar Threads
- How to store each line of text file using getline() function (C++)
- Help printing line from file and line number (C++)
- search in text file (C++)
- Fstream Help (C++)
- Seperate each string from line?? (C++)
- Command Line textfile (C++)
- FStream question--delimiters (C++)
- Use line by line from a textfile. (C++)
- fstream - replace line (C++)
Other Threads in the C++ Forum
- Previous Thread: Questions on vector
- Next Thread: vs2008 fstream open() fails
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






