Hi ,
I have this code which is capable to read from file only one column , I need it read two column. So, how can I alter it to read from file and place the value in array ?
Note : the data file format like that :
QTextStream in(&file);
unsignedint max_lines = 20000; // we choose 102 because in the real file there are two header lines in the top of file
float data[max_lines];
unsignedint lines_read =0;
for(int i=lines_read ;i<max_lines;i++)
{
double x;
QString content;
in >> x;
content = content.setNum(x);
data[i]=content.toDouble();
in.readLine();
lines_read++;
}
The body of the for loop is confusing me, why do you need to go through all of that rather than simply casting to a float? Is there a hardware limitation that makes that slow? I can't see a cast to a string and back again being faster than the built int float<>double casting even if it's done in software.
Anyways, back to the question. The simplest would simply be to make data a multi-dimensional array:
1 2 3 4 5 6 7 8
float data[max_lines][2];
...
for ( each row ) {
//read first col
data[i][0] = //value from first col
//read second col
data[i][1] = //value from second col
}