Reading file help

This is a discussion on Reading file help within the C++ Programming forums, part of the General Programming Boards category; I have a file that has three players names and how many touchdowns scored and how many catches they have ...

Reading file help

I have a file that has three players names and how many touchdowns scored and how many catches they have caught. I know the code for opening up the file and reading it but I dont understand how to add each category. For example the file is like this.

John
2: 5
Micheal
1: 4
Patrick
2: 7

So for the output I want it to read:
Touchdowns: 5
Catches: 16

I know the output code is
cout<<"Touchdowns: "<<touchdown<<endl;
cout<<"Catches: "<<catches<<endl;

No I do not. How do you do that? Is that the basis for adding numbers in a file?

Yes. Imagine that you and a friend are supposed to add up some numbers, but he has the list of numbers, you have the calculator, and you're talking on the phone so you're stuck. He's going to read off the numbers and you're going to add them up -- how do you do it?

Once you do that, you should be able to write a C program that does the same thing -- the file is the list of numbers, and the scanf/getline/whatever input functions will read them off to you and you have to add them.

I thought while (inFile>>scored) would read the scores file and store them in the variable scored.

It would. Do you want things like "John" and "Patrick" to be read into an integer variable? You have to read the data that's there and know what it is; read in
*a name
*touchdowns
*a colon ( : )
*catches
each time through.

Im not totally understanding. So are you saying that I cant use that because the first item is not "scored" but a name.
So if I used that it would read in Patrick and John as the variable scored.
So how do I tell it to read in the just the score portion.