Hi everyone, I am having trouble "undoing" this method, that dumps essentially a matrix of numbers of variable size into a text file:
void vectorToFile(char *name, vector<vector<double>>* a){
FILE* fp = fopen(name, "w");
for(int i=0;i<a->size();i++){
for(int j=0;j<a->at(i).size();j++){
fprintf(fp, "%f ", a->at(i).at(j));
}
fprintf(fp, "\n");
}
fclose(fp);
}
I am having trouble implementing the reverse:
vector<vector<double>> fileToVector(char *name){ ??? }
I am guaranteed that the numbers in the file form a "rectangle", i.e. the sizes of inner vectors are all equal, but I don't know how to figure out the number of entries per row, and the number of columns.
Can anyone point me in the right direction? Every example I found so far implements something much easier, with hardcoded size, or sizes given in first row (which I cannot afford to do unfortunately)