PDA

View Full Version : read from file two lines



mmm286
23rd October 2009, 22:21
Hi,

I try to read from file two lines, and each line is allocated to a QString. I know how read the file line by line but not two lines at the same time.
It's possible?Could you help me?

Many thanks and sorry for my english!

wysota
23rd October 2009, 22:36
Hmmm... is this question serious? You know how to read one line but you don't know how to read two lines? Did you try reading one line and then reading another line again? This should give you a total of how many lines read?

mmm286
23rd October 2009, 22:57
Hmmm... is this question serious? You know how to read one line but you don't know how to read two lines? Did you try reading one line and then reading another line again? This should give you a total of how many lines read?

Sorry there are a lot of hours programming jejeje;
Many thanks!

calhal
23rd October 2009, 22:59
I try to read from file two lines, and each line is allocated to a QString. I know how read the file line by line but not two lines at the same time.
It's possible?Could you help me?

I think you have to run a level 3 diagnostic

wysota
23rd October 2009, 23:17
I think you have to run a level 3 diagnostic

Make it so, number one! :cool:

mmm286
26th October 2009, 10:53
Sorry I think that I don't explain very well.

Imagine that I have a file like this:

2004
2008
2010
2013
....

I read this file line by line. I must do:

read first_line
If first_line > 2005 then
read second_line
if second_line > 2006 then
....
...

Everything it's ok but when I read the second line, when the program goes to the begining, the code reads next line (that is the third line), and I would like that the program reads the second line and so on.

I hope you can understand me :-(

calhal
26th October 2009, 12:42
Could you explain what exactly this program is supposed to do?

Maybe it would be better if you read whole file at once like this:

QStringList slist = QString(file.readAll()).split("\n");
And then you can access each line very easily.

Anyway I'm not sure what do you want to achieve.