Ignoring random newlines while reading from a file.

I'm having trouble properly reading files while there may be random newlines in between the input file.

My code looks like this, it is looped in a while(!input.eof())
void person::read_from_file(ifstream & input)
{
getline(input, name);
getline(input, major);
input>>age;
input>>height;
input>>weight;
input>>gpa;
input>>worth;
grade = calc_grade(gpa);
calc_feet(height);
calc_inches(height);
input.ignore(20,'\n');
}


an example of a random input file looks like this:





Gate,Bill

Computer Science
47 76 225 2.0 59000000000.0
Bush, George W.

Business Admin.
54 78 240 2.2 12000000.0
Einstein, Albert

Physics
76 69 180 4.0 100000.0

Brown, Nancy
Elementry Education
43 67 130 3.6 520000.0
Anderson, Harry
Chemical Engineering
28 72 190 3.2 56000.0
Williams, Laila
Civil Engineering
23 70 120 3.7 12000.0


How can I take into consideration that there may be random newlines in between my data as I read?

I've tried using cin.ignore(100,'\n') but that only works if I know for sure where the newlines are.

I'm having trouble properly reading the files in the loop statement if they're placed randomly.
Last edited on
seams like an issue with your outputs, could you post the part of the code holding your cout's?
Posting the whole code would be more helpful, but if it's really long and if I'm right about your outputs then just the outputs would probably work.
Last edited on
Topic archived. No new replies allowed.