您好,我的问题看起来很简单,但我试图从文本文件中读取大量数字,但未能正确执行!!!
看看以下文件保存在file1.text
我有一个如下结构:
struct PDW_FileFormat
{
float TOA;
float Freq;
float PW;
float PA[10];
float PASlc1;
float PASlc2;
float PAOmni;
float AZ_Angle;
float EL_Angle;
float EST_Az_Angle;
float EST_El_Angle;
float Cdiff;
unsigned int index_in_packet;
};
并像下面的代码一样打开和读取文件
PDW_FileFormat filedata;
unsigned index_in_packet=0;
p = fopen("file1.txt" ,"r");
while (!feof(p))
{
memset(&filedata,0,sizeof(PDW_FileFormat));
fscanf(p ,"%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f"
,&filedata.TOA //1
,&filedata.Freq //2
,&filedata.PW //3
,&filedata.PA[0] //4
,&filedata.PA[1] //5
,&filedata.PA[2] //6
,&filedata.PA[3] //7
,&filedata.PA[4] //8
,&filedata.PA[5] //9
,&filedata.PA[6] //10
,&filedata.PA[7] //11
,&filedata.PA[8] //12
,&filedata.PA[9] //13
,&filedata.PASlc1 //14
,&filedata.PASlc2 //15
,&filedata.PAOmni //16
,&filedata.AZ_Angle //17
,&filedata.EL_Angle); //18
filedata.index_in_packet = index_in_packet;
// some code to convert a value like
// 1.386500000000000e+10
// to
// 138650000000000
INT64 TOAConvert;
//**your code or your answer **
index_in_packet++;
}
我已经尝试过这些代码,但对我来说不能正常工作
//filedata.TOA = 1.3865000e+010
INT64 variabletoConvert;
stringstream ss;
ss.setf(ios::fixed);
ss.precision(0);
ss << filedata.TOA;
ss >> variabletoConvert;
// variabletoConvert = 13864999936 i expect 138650000000000
INT64 variabletoConvert2;
variabletoConvert2 = static_cast<INT64>(filedata.TOA);
//variabletoConvert2 = 13864999936 i expect 138650000000000
INT64 variabletoConvert3;
variabletoConvert3 = (INT64)(filedata.TOA);
//variabletoConvert3 = 13864999936 i expect 138650000000000
看看这个调试图像: