Parse value from text file

Suppose i have a text file with ":" as delimiter, how to i find the average value of each column? For e.g. First column will be (3+2+5)/3 and second column will be (61+87)/2 for the third column.

Sample text file
================
3:290:61:100:
2:50:
5:346:87:

I have tried using getline in while loop, but it seemed more complicated because i think it requires much more than that. So i will appreciate if anyone can enlighten me on this. Thanks!
Use a linked list data structure where each element of the list is a pair of values (sum, count).
STL has such a thing for you:
http://www.cplusplus.com/reference/forward_list/forward_list/forward_list/
http://www.cplusplus.com/reference/utility/pair/pair/
Smac89 idea is probably best in your case (However I would use vector to store pairs), but if you need to store all values to manipulate them later, you can read file line by line and parse these lines (using getline again as standard library does not have adequate tokenizers)

http://ideone.com/ggCHoA
Topic archived. No new replies allowed.