Reading line by line in a large text file

X

xyz

Hi,
I have a text file around 7GB includes 100 million lines...
I want to read the data line by line when I approach my module..

ie., when i read for the first time , my program shuld read only one
line
and when i read for the next time , my program shuld read only second
line discarding first line..

i did it with ignore function but it is taking lot of time to reach
end of file...

please give me a simple approch to do this..

thanks to all
 
L

Lars Uffmann

xyz said:
I have a text file around 7GB includes 100 million lines...
I want to read the data line by line when I approach my module..

ie., when i read for the first time , my program shuld read only one
line and when i read for the next time , my program shuld read only
second line discarding first line..

I'm not sure what you mean by "first time" and "next time" - do you mean
subsequent read calls with the open file, or do you mean reading a line,
closing the file, then opening it again and now reading the 2nd line?

In the first case, I don't see the problem, because you just read one
line after another.

In the second case, you'll need to store a filepointer somewhere
(variable or config file) - to the position AFTER your last read (i.e.
the first byte of the succeeding line). Then when you re-open the text
file, just jump to that file pointer and continue reading.

For info on ftell & fseek, check the c++ reference:
http://www.cplusplus.com/reference/clibrary/cstdio/ftell.html


Best Regards,

Lars
 
X

xyz

I'm not sure what you mean by "first time" and "next time" - do you mean
subsequent read calls with the open file, or do you mean reading a line,
closing the file, then opening it again and now reading the 2nd line?

In the first case, I don't see the problem, because you just read one
line after another.

In the second case, you'll need to store a filepointer somewhere
(variable or config file) - to the position AFTER your last read (i.e.
the first byte of the succeeding line). Then when you re-open the text
file, just jump to that file pointer and continue reading.

For info on ftell & fseek, check the c++ reference:http://www.cplusplus.com/reference/clibrary/cstdio/ftell.html

Best Regards,

   Lars

What i mean is....i want the second case...
i tried storing the file positon after reading the line...
but i couldnt succeed...
could you please get some more details
 
X

xyz

What i mean is....i want the second case...
i tried storing the file positon after reading the line...
but i couldnt succeed...
could you please get some more details

i got it...thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top