View Full Version : reading/writing to file
QiT
8th August 2006, 08:38
hi:)
I have a file with this structure:
15 12 36
25 45 36
12 48 20
i used out << int1 << "\t"<<int2 << "\t"<<int3 <<endl; to write it;
but when i use
in >> int11 >> int12 >>int13; i do not have correct results
what can i do?:confused:
e8johan
8th August 2006, 13:51
I would recommend reading one line at a time and splitting it on tabs (pretty much as is done in this example, only that it is splitting on colons http://doc.trolltech.com/3.3/tutorial2-03.html - look for the implementation of operator>> )
windkracht8
11th August 2006, 17:21
Also posible:
out << int1 << "\t"<<int2 << "\t"<<int3 <<endl;
in >> int1;
in >> int2;
in >> int3;
That's how I would do it.
Or:
QStringList tsTemp;
QString sTemp;
out << int1 << "\t"<<int2 << "\t"<<int3 <<endl;
sTemp = in.readLine();
tsTemp = sTemp.split("\t");
int1 = tsTemp.at(0);
int2 = tsTemp.at(1);
int3 = tsTemp.at(2);
Cheers,
Bart.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.