Read Words From File Into Array C++
-             
1st Baronial 2010,08:49 #1
                read from file into assortment              Hello ,
I have this code which is capable to read from file only one cavalcade , I need it read two cavalcade. So, how tin I alter it to read from file and place the value in assortment ?
Notation : the data file format similar that :10.ii 30.3 12.4 ........
34.56 45.ix 34.5.......
12.3 12.45 10.10.....
.
.
.-                             
unsigned int max_lines = 20000; // nosotros choose 102 because in the real file in that location are two header lines in the top of file
 -                             
bladder data[max_lines];
 -                             
unsigned int lines_read = 0;
 -                             
for ( int i=lines_read ;i<max_lines;i++ )
 -                             
{
 -                             
double x;
 -                             
in >> x;
 -                             
content = content.setNum (x);
 -                             
information[i] =content.toDouble ( );
 -                             
in.readLine ( );
 -                             
lines_read++;
 -                             
}
 
QTextStream in(&file); unsigned int max_lines = 20000; // we cull 102 because in the real file there are ii header lines in the top of file bladder data[max_lines]; unsigned int lines_read =0; for(int i=lines_read ;i<max_lines;i++) { double ten; QString content; in >> x; content = content.setNum(x); data[i]=content.toDouble(); in.readLine(); lines_read++; }To copy to clipboard, switch view to plain text mode
 -                             
 -             
1st August 2010,09:26 #2
                Re: read from file into array              Read both of the values you desire into variables within your loop trunk. If you lot demand to skip a value in the middle, read it into a dummy variable.\\
Why are y'all using both the input operator (>>) and readline()? As well, why not merely read directly into your array instead of performing all the conversions? And since data[] is an array of float, why are you converting to a double?
 
Source: https://qtcentre.org/threads/32950-read-from-file-into-array
0 Response to "Read Words From File Into Array C++"
Post a Comment