我正在尝试读取此 .csv 文件,这是数据示例:
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
问题出在第一列第 1 行和第 2 行。在 excel 文件中,它说单元格中的数字显示为 1.33286E+12,当您单击单元格时,它说它们是 1332856031313 和 1332856031328,但程序正在读取它们如 1.33286E+12 但我需要整数 1332856031313 和 1332856031328。
编码:
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();