reading multiple lines of input using infile?

Hello, I have a file I need to read from, with student names, their class, and their grades in the class. Right now, the code I have can read the first 3 students correctly, but once it gets to the fourth, it starts using grades from previous students.

For example, this is the file i am reading from

1
2
3
4
5
6
7
8
9
10
11
5
Smith, John
Computer Science 70 75 80 75 90 100 50 96 76
White, Joe
Biology 83 56 86 90 84
Brown, Marvin
Theater 75 80 72
Scoop, Milly
Computer Science 45 57 26 79 54 52 74 60 45
Can, Homer 
Theater 82 78 85


Smith, White, and Brown are all read in correctly, but for Scoop instead of reading in 45 57 26 79 54 52 74 60 45, it is reading in 75 80 72 90 84 100 50 96 76 for the 9 grades.

So how would I clear out g1-g9 for when the second person in that class is being read in?

Last edited on
Probably has something to do with the extraction stream. I don't know if this will fix it, but you should use getline for those string variables of filenames.
getline wouldnt work for getting the ints though would it?
Topic archived. No new replies allowed.