Skip to main content

Thread: C++ not reading entire file


hi everyone!

having dificulties trying read big .csv file (a few thousand lines). problem reading stops after 4000 lines (typically before 4600) , can't figure out why. number of last line reached varies each run.

see there lines (after line 4800) empty or have incorrect format, never reached doubt problem.

attached file trying read. take care of first 5 lines without problem. when have read actual data need, can't reach end of file. according netbeans, run successful "run successful ".

here's code trying read +6th lines:

code:
void filereader::readstardata(star* star, istream* stream) {      string data;      int = 5;      while(std::getline(*stream, data, ',')) {          stardata sdata;          sdata.quarter = strtof(data.c_str(), null);                    std::getline(*stream, data, ',');          sdata.time = strtod(data.c_str(), null);                    std::getline(*stream, data, ',');          sdata.brightness = strtod(data.c_str(), null);                    std::getline(*stream, data, ',');          sdata.error = strtod(data.c_str(), null);                    i++;          cout << << ": ";          cout << sdata.quarter << " ";          cout << sdata.time << " ";          cout << sdata.brightness << " ";          cout << sdata.error << " " << endl;      }  }
where stardata is:

code:
struct stardata {      float quarter;      double time; //days      double brightness;      double error; //error in brightness  };
le: forgot add attachment.
attached files attached files

there no error checking in code stops when reaches differently formated lines @ lines 1644, 3245 etc.

might want use typesafe stream extraction operators instead of not-typesafe c ones.
e.g. convert string getline stringstream , use >>
(or use >>)


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk C++ not reading entire file


Ubuntu

Comments

Popular posts from this blog

How to set the order of FAQs instead of alphabetical

Thread: Get UK Keyboard working

how do I change the e-mail address for my merchant account