found this lib for csv parsing https://github.com/ben-strasser/fast-cpp-csv-parser and I am trying to get the data into 2d array. I have a problem with useability as the lib is constructed in a specific manner
bool read_row(ColType1&col1, ColType2&col2, ...);
Going from example presented in github, I came up with:
main() {
double** data = new double*[5];
for (int i = 0; i < 4; ++i) {
data[i] = new double[5];
}
io::CSVReader<5> in("c:/code/test.txt");
//in.read_header(io::ignore_extra_column, "vendor", "size", "speed");
double a; double b; double c; double d; double e;
int n = 0;
while (in.read_row(a, b, c, d, e)) {
printf("time elapse: %f\n", c);
data[n][0] = a;
data[n][1] = b;
data[n][2] = c;
data[n][3] = d;
data[n][4] = e;
n++;
}
for (int i = 0; i < 4; i++){
for (int j = 0; j < 5; j++) {
printf("data %f\n", data[i][j]);
}
}
}
This does the job, goes through 4 lines with 5 columns and as to example I had to present a variable for every column. How to modify the code to take thousands of columns? Is there a better/easier way to process csv into 2d array? My goal is speed, I know exact formating of csv input, num of lines and columns, so no checks needed.