I am trying to read this .csv file and here is an example of the data:
1.33286E+12 0 -20.790001 -4.49 -0.762739 -3.364226 -8.962189
1.33286E+12 0 -21.059999 -4.46 -0.721878 -3.255263 -8.989429
The problem is with the first column row 1 and 2. In the excel file it says the numbers in the cells are displayed as 1.33286E+12 and when you click on the cell it says they are 1332856031313 and 1332856031328 but the program is reading them as 1.33286E+12 but I need the whole number 1332856031313 and 1332856031328.
The code:
inputfile.open(word1.c_str());
while (getline (inputfile, line)) //while line reads good
{
istringstream linestream(line); //allows manipulation of string
string str;
while (getline (linestream, item, ',')) //extract character and store in item until ','
{
char * cstr, *p;
cstr = new char [item.size()+1];
strcpy(cstr, item.c_str());
p = strtok(cstr, " ");
while (p!=NULL) //while not at the end loop
{ // double e = atof(p); // coverts p to double
value++;
if( value == 1)
{ double e = atof(p); // coverts p to double
if(m ==1)
cout << time[0]<<"\n";
ostringstream str1;
str1 << e;
str = str1.str();
string str2;
str2.append(str.begin(), str.end());
const char * convert = str2.c_str();
e = atof(convert);
time[m] = e*0.001;
m++;
//if(m >=192542)
//cout << time[m-1]<<"\n";
}
p = strtok(NULL, " ");
}
delete[] cstr; //delete cstr to free up space.
}
count ++;
value = 0;
}
inputfile.close();
If the number 1332856031313 is being serialised as 1.33286E+12, there is no way to get it back in the deserialisation process. Information in the form of those 6 extra significant digits is gone forever. You need to make sure that when the CSV file is generated, it is saved at full precision. I don’t know how you might do this with Excel.
Also, your use of
atofandconst char*isn’t very C++-esque. Consider using code likeinstead.