r/learnprogramming•
Mythnam

.eof loop only takes input once? (C++)

Well after four hours of searching, tweaking, and making little progress I've gotten kind of frustrated. I'm sure there's an easier way of doing this, but the instructions for my assignment specifically state that I need to use a linked list of structs.

Anyway, in this function I'm trying to take input from a file (an ID number and a change in that person's weight), compare it to the ID of each member of the linked list, and change the weight if the IDs match.

The problem seems to be that the loop is only taking the first set of input from the file and not reading the next line of the file when the loop repeats. If I remove line 18 it applies the first change to the whole list, so I think the problem is either in the .eof loop or the location of the extraction.

So, why isn't the function taking new input? Why does the .eof loop finish itself if it's not reading the next line? I feel like I'm missing something simple, but I don't know what.

Posted Dec 2, 2011, 4:27 AM UTC

310
Loading comments…