fstream - c++ ifstream Skipping Data -
i'm trying program read 2 lines out of 6 line data file (the other 4 2 sets of 2 meant read other objects). however, can read 1 -- either first or second depending on how manipulate code.
here's what's in data file:
mustang sally 123.45 george porge 11.99 j. d. rockerfeller 56321.3
and here's section of code need read said data:
void account::readaccount(ifstream &infile) { while (getline(infile, name)) { infile.ignore(); infile >> savings; } }
the code above reading in second line.
i think i'm having phantom newline problem, can't seem resolve, feel there's problem on top of that, can't comprehend current level of experience regarding file streams.
the code above reading in second line.
yes because tell ignore
. don't know 2 lines want these, based on codes, i'm assuming want read values @ line 2,4
. following code print out 2 lines.
float savings = 0.0f; while(getline(infile,line)) { if(savings > 0.0f) cout << savings << endl; infile >> savings; infile.ignore(1000, '\n' ); }
Comments
Post a Comment