How to using ifstream to read a txt file line by line from end to begin?

How to using ifstream to read a txt file line by line from end to begin?

Post by i386 » Tue, 22 Jun 2004 15:32:41



 
 
 

How to using ifstream to read a txt file line by line from end to begin?

Post by Agoston Be » Tue, 29 Jun 2004 03:26:49

See the getline() member function.

Gus

 
 
 

How to using ifstream to read a txt file line by line from end to begin?

Post by tom_usene » Tue, 29 Jun 2004 18:56:48

On Mon, 21 Jun 2004 14:32:41 +0800, "i386" < XXXX@XXXXX.COM >


1. Choose a buffer size, say N=256.
2. Seek to the end
3. Seek back N chars
4. Read in N chars
5. scan for newlines. Copy in complete lines
6. If at start, stop, else seek back N chars and repeat from 3.

IOW, there is no short cut - just read chunks from the end, an scan
for newlines in the string.

Tom
--
C++ FAQ: http://www.yqcomputer.com/ ++-faq-lite/
C FAQ: http://www.yqcomputer.com/ ~scs/C-faq/top.html