Read Words From File Into Array C++

  1. #1

    Default 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.....
    .
    .
    .

                          
                            
    1. 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

    2. bladder data[max_lines];

    3. unsigned int lines_read = 0;

    4. for ( int i=lines_read ;i<max_lines;i++ )

    5. {

    6. double x;

    7. in >> x;

    8. content = content.setNum (x);

    9. information[i] =content.toDouble ( );

    10. in.readLine ( );

    11. lines_read++;

    12. }

    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


  2. #2

    Default 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?


higginshards1980.blogspot.com

Source: https://qtcentre.org/threads/32950-read-from-file-into-array

0 Response to "Read Words From File Into Array C++"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel