I tried to simply copy/paste this info and run it, but received some errors |
I just gave you a high level. Since you seemed okay with the vector<string> we used for the header row, I assumed you could extend the idea.
This snippet was just to give you the idea.
vector<vector<double>> data;
A vector<double> is an arbitrary length array of doubles. This represents a "row". You can push as many doubles on to the vector as you have columns in the row.
typedef vector<double> ROW;
Here we created a new data type called ROW. A ROW is simply an array of doubles as I just explained. vectors of vectors can be confusing to think about, but a vector of ROWs is simply an arbitrary length array of ROW objects.
vector<ROW> vdata;
Here we create a vector of ROWs called vdata. As we read lines from the file, we create a temporary ROW object and push each column (double) from the line onto the temporary row, then at the end of line we push the temp row onto the vdata vector.
Finding the number of rows is simply:
1 2
|
num_rows = vdata.size();
|
Finding the number of columns depends on whether the rows are all the same length, or if they can vary in length. If the rows all have the same number of coulmns, then you can get the number of columns from the lablels vector:
|
num_cols = labels.size();
|
If the rows have different number of columns, then you need to iterate through vdata, finding the row with the largest size.