Here is something that I have been using, just read everything in with the first function and use the second function to separate the data by column.
LINE is a global typedef of vector<string> used to store each line of a CSV file, so the very first line will hold the column titles, which is used by the second function to separate the columns.
I almost forgot, stats is also global, but this was just a temporary fix, in the final prog it is not global:
// Reads the datafile into vector stats
vector<LINE> readFile(const char *filename)
cout << "Failed to open file" << endl;
while( (pos = line.find(',')) >= 0)
line = line.substr(pos+1);
// Parses the vector into rows of information by column and returns the row
string GetColData(int row_number, string ColName)
LINE &columnNames = stats;
// find the column with the above column name
for(int column = 0; column < columnNames.size(); column++)
if( ColName == columnNames[column] )
// get data for this column
LINE &row = stats[row_number];