1) My input: A csv (or txt) file of integers (indexes) of arbitrary (and unlimited) number of columns and rows, such as for example
0, 1
2, 3, 4
2) Desired output: Store the integer file into a data structure. I suspect the best such data structure capable of accommodating the flexible size would be a vector of vectors.
3) What I've done so far, what remains to be done: I've completed a first stage and more trivial problem where I read a formatted nx2 csv file into two arrays. This program is the following is shown below.
The question then is how do I extend this to the nxm (instead of nx2) file size and store into vector of vectors instead of two arrays?
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include<vector>
using namespace std;
int main(){
//define variables
string ind, p; //variables from file are here (two columns)
vector<int>index;
vector<float>prob;
//number of lines
int i=0;
ifstream input;
input.open("Params05.csv"); // Params is the nx2 input file
while(input.good()){
//ignore first line
string line;
getline(input, line);
// Two getlines for two columns (sets)
getline(input, ind, ',');
index.push_back(stoi(ind));
getline(input, p, '\n'); //newline
prob.push_back(stof(p));
i += 1; //increment total number of laws
}
input.close(); //close file
cout<< "Number of entries: "<< i-1 << endl;
for (int j = 0; j < i; j++){
cout<< index[j] << "\t" << prob[j] << endl;
}
}
Thanks in advance for any thoughts, tips and contributions. Love this forum.