You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

  • "grsandeep85" is male
  • "grsandeep85" started this thread

Posts: 39

Location: INDIA(Bangalore)

Occupation: Design Engineer

  • Send private message

1

Thursday, July 30th 2009, 10:30am

how to read line number in a text file

Hi All,

have a text file in the format
#n X Y Z
0 123 456 789
1 321 654 987
2 345 243 809
......
.....
...... and so on
i have implemented the code which reads the contents of file and display in the console along with the line numbers, here is my code

QStringList lines;
QString result;
QFile file( "datum.txt" );
if ( file.open( IO_ReadWrite ) ) {
QTextStream stream( &file );
QString line;
linenumber = 0;
while ( !stream.atEnd() ) {
line = stream.readLine( );
printf( "%3d: %s\n", linenumber++, line.latin1() );
lines +=line;
}
file.close();
}

now how read the particular line number in a text file(say line number 3) and its contents.please help us it would be a great pleasure.
Thanks & Regards
Sandeep G R

profox

Trainee

  • "profox" is male

Posts: 111

Location: Belgium

  • Send private message

2

Thursday, July 30th 2009, 3:04pm

I don't understand your question.
You want to read a particular line number from the file in a QString?
I think that's not possible. You have to actually read through the file itself, just like you are doing now.