sheepdonkey
April 14th, 2006, 09:09 AM
Is there a way to find out how long a line is in my csv file (e.g. how many variables). I'm reading the data into a string and then using stringstream (a method a picked up from this excellent forum!) to input into an array:
std::ifstream ifs(filename);
std::string line, field;
double* pArray = new double[11];
std::getline(ifs,line);
std::stringstream ss(line);
for(int i=0; i<11; i++)
{
ss>>pArray[i];
std::getline(ss,field,',');
}
Also, is this method accurate, as when I'm debugging and stepping through I see values change ever so slightly from what they are in the CSV file.
e.g.
0.4 in a CSV would be 0.4000000002
std::ifstream ifs(filename);
std::string line, field;
double* pArray = new double[11];
std::getline(ifs,line);
std::stringstream ss(line);
for(int i=0; i<11; i++)
{
ss>>pArray[i];
std::getline(ss,field,',');
}
Also, is this method accurate, as when I'm debugging and stepping through I see values change ever so slightly from what they are in the CSV file.
e.g.
0.4 in a CSV would be 0.4000000002