0

您好,我的问题看起来很简单,但我试图从文本文件中读取大量数字,但未能正确执行!!!

看看以下文件保存在file1.text 文件1.文本

我有一个如下结构:

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 

看看这个调试图像: 在此处输入图像描述

4

1 回答 1

0

好吧,我已经完成了这个解决方案,但它涵盖了巨大数字的一部分,如果有人发布了一个检索完整数字的解决方案,我会将其标记为答案是否有可能恢复一个强制保存在 4 字节浮点数中的数字.. ……!!

#include "stdafx.h"
#include <iostream>
#include <math.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
    float inputvalue;
    std::cout <<"Enter a large number" <<endl
              <<"system will save it in a float variable" <<endl
              <<"Your Number =";
    std::cin >> inputvalue;
    float temp;
    temp = inputvalue;
    int numberDigits =0;
    double DivisionCount= 1;
    while (temp > 1)
    {
        numberDigits++;
        DivisionCount*=10;
        temp = temp / 10;
    }
    temp = inputvalue;
    int middlevar=0;
    double Outputvalue=0;
    for (int i =0;i < numberDigits ; i++)
    {
    DivisionCount /= 10;
    middlevar =temp / DivisionCount;
    temp = temp - (middlevar * DivisionCount);
    Outputvalue *= 10;
    Outputvalue+= middlevar;
    }
     cout << endl << "Your value saved in memmory"<<Outputvalue;
    cin.get();
    cin.get();
    return 0;
}
于 2013-03-01T19:59:15.493 回答