I know the topic has been discussed a lot but I still don't really get it. Admittedly I am pretty new to C++ coding, so please go easy on me :)
Anyhow: I have this examplatory csv file:
,313,315
91.5919,1.44421,1.74019
91.592,1.44254,1.73816
91.5921,1.43859,1.73336
91.5922,1.43449,1.73109
I need an array with unknown dimensions a priori, since the csv will expand unpredictably -> dynamic array in both x and y direction.
This is what I managed to do so far:
#include <algorithm>
#include <fstream>
#include <iostream>
#include <iterator>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<vector<double> > values;
vector<double> valueline;
ifstream fin("in.csv");
string item;
for (string line; getline(fin, line); )
{
istringstream in(line);
while (getline(in, item, ','))
{
valueline.push_back(atof(item.c_str()));
}
values.push_back(valueline);
valueline.clear();
}
}
It appears to be doing the job, but if I try to output the array or parts of it, I get strange results. For example cout << values[0][3] << endl; yields 1.63042e-322. values[0][4] yields 91.5919. Also sizeof(values[0]) is 24.
Am I doing something I am not supposed to here?
Any help would be great! Thanks