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:
where stardata is: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; } }
le: forgot add attachment.code:struct stardata { float quarter; double time; //days double brightness; double error; //error in brightness };
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
Post a Comment