Hi. I'm working on a problem where you read data from a file, accumulate a total, and then output the data and total. The data looks something like this:
7 21 361 John Smith 48 19.95
The problem is that when the data is output, it outputs the string part as a 0 and never generates the numbers after that. Also, it creates an infinite loop of those first three numbers and never goes to the next line. I know it has something to do with the string, but I don't know what to do when the string is in the middle of the line and there are different data values before and after it.
When reading strings, the >> formatted input operator stops
reading the string when it encounters a white space character.
Spaces, tabs and carriage returns are all white space characters.
This means that John Smith is actually 2 strings.
So you should be reading the line as follows: int int int string string int floatinFile >> num1 >> num2 >> num3 >> charName1 >> charName2 >> num4 >> num5