Working with text files

Not sure if this is the right place to ask a question since I've been looking for an answer on the internet but couldn't find I thought that I might ask here. So I have a problem. I have a text file example :
R 10
G 15
Z 13
R 5
R 6

My question is how do I add and get the sum of R?
Hi DdavidDLT,

I think you could do the following:

_for every line beginning with 'R', read line to a string variable.
_extract the number to convert it to an int
_create a count int and increment it with the values you converted from the strings beginning with the char R
Hello DdavidDLT,

Because the input file has a space between the letter and the number you could do something like: while (inFile >> letter >> number);. In the while loop check if "letter" matches what you want and do a += to a total. After the while you can print out something with total.

Hope that helps,

Andy
Good point Andy, that's actually way more logical and practical to do.
@HOOGO,

Thank you.
well, if you are being practical, open it in excel.. :P
Topic archived. No new replies allowed.