C++: How do you calculate the sums of columns in comma separated values?
===

I'm dealing with a slightly specific problem. I have a program which grabs tables from the web in JSON format and converts them to CSVs. The tables are dynamic in size and include a header row with text. One table might look like:

    DataCode,AreaName,AreaID,Population
    G1000,Billford,15,21000
    G1001,Millville,18,21000

Assuming I don't know how big the array is going to be, I would like to be able to take the sum of ONLY the population statistic. (I will have the header for the column for which I want the data stored in a variable, in this case "population" but it changes dynamically as well.)

When consolidating multiple tables, I also have the issue that duplicate entries are difficult to remove. For example a combined table may look like:

    DataCode,AreaName,AreaID,Population
    G1000,Billford,15,21000
    G1001,Millville,18,21000
    DataCode,AreaName,AreaID,Population
    G1003,Brinton,21,26000
    G1004,Nixon,24,12000

I'm mystified by how to create a function that can take a table of any size in CSV or JSON format, and take the sum of only the numbers in a given column.