Reading data from file C++ -
i have these set of data in .txt log file:
2016-01-17 red 1 2 2.252016-01-18 blue 3 1 1.34 i stored vector, , code looks this:
while(!logfile.eof()) { getline(logfile, l.date, ' '); getline(logfile, l.color, ' '); logfile >> l.minusage; logfile >> l.maxusage; logfile >> l.ratio; logfile.ignore(1000, ' '); log.push_back(l); } log's datatype vector<record> record class. wanted values when i'm printing it:
2016-01-17 red 1 2 2.25 2016-01-18 blue 3 1 1.34 but instead got output:
2016-01-17 red 1 2 2.25 blue 3 1 0 1.34 the second line doesn't store value of date second set of data .txt file.
how separate 2.252016-01-18 .txt file 2 different entries 2.25 , 2016-01-18 ?
never use !logfile.eof() test end of input doesn't return true @ end of input. use getline instead, like:
while ((getline(logfile, l.date, ' ') && (getline(logfile, l.color, ' ')) { // ...
Comments
Post a Comment