Hello. I'm running into a problem on an assignment I have for my C++ class. I've done similar things before with reading a file, but normally used a counter to know when to stop reading from a line and go on to the next, or code like this:
ifstream inFile;
inFile.get(ch);
while (ch != '\n' )
However, I cannot figure out how to accomplish this with the program I'm currently making. Here's the data I'm reading from a file:
George Bush 70 77
Barack Obama 70 75 80
Bill Clinton 68 70
The point of the program is to read the names and grades and average them out, but I don't need help with that. I need help with how to have the program read in grades until it reaches the end of the line, and then stopping and going on to the next line. It needs to be able to work with ANY set of data formatted in the same way, with any number of grades. I've tried all I know, but I can't figure out a way to insert a while or if statement using '\n' as the "stop and go to the next line" value. Everything I've tried is leading to garbled output or no output at all.
So, the goal is to read firstname and lastname.
inFile >> firstName >> lastName;
Then read in a grade, perform the mathematical calculations on it, and continue on until there are no more grades left on the line. Again, this needs to work with any properly formatted data. What I provided is a sample. So how can I make it stop reading grades and go to the next line? If you could provide me with some direction or code sample on how I can accomplish this I'd greatly appreciate it.