C 从没有STL的用户输入中获得CSVWITH的最大值

C++ Getting maximum value from CSVwith year and month from user input without STL

本文关键字:最大值 CSVWITH 输入 用户 STL      更新时间:2023-10-16

我试图从 csv 文件中读取具有以下值的读取。 DateTime ,DP,DTA,DTS,EV,QFE,QFF,QFF,QNH,R,RH,rh, speed radiation ,ST,ST,ST2,ST2,ST2,ST3,ST3,st4,sx,t

31/03/2016 9:00 14.6 175 17 0 1013.4 1016.9 1017 0 68.2 6 512 22.7 22.7 24.1 25.5 25.5 26.1 8 20.74 20.74 31/03/2016 9:10 14.6 194 22 0.1 1013.4 1016.9 1017 1017 0 67.2 5 565 22.7 22.7 25.5 25.5 25.5 26.1 8 20.97 20.97

当前我需要数据的列是来自DateTime,速度和辐射。但是,当我致电Windlog.print时,DateTime从第二行开始打印每条备用行,并从第三行开始打印辐射,因此我想知道我对忽略函数有任何错误吗?cus我对此不太农业。

关键问题是我们不应该使用任何STL数据结构。我为此写了一个简单的向量类。

typedef struct
{
 Date d;
 Time t;
 float speed;
 int solar;
}
W;
//Methods
void getMaxSpeed(int y2, int m2);
//var
int choice, year,m, tt;
ifstream input;
string filename,month,num;
Vector<W> windlog;
W T1;
ostream & operator << (ostream & osObject, const WindLogType & W1);
istream & operator >> (istream & input, WindLogType & W1);
int main()
{
 filename = "test.csv";
 string line2,line,sDay, sMonth, sYear, sHH, sMM;
 input.open(filename.c_str());
 input.ignore(500,'n');
 if(!input.is_open())
 {
    cout<< "File not found."<<endl;
    return 0;
 }
 else
 {
    while(getline(input,line))
    {
        //Get Date
        getline(input, sDay,'/');
        getline(input, sMonth,'/');
        getline(input, sYear,' ');
        //Get Time
        getline(input, sHH,':');
        getline(input, sMM,',');
        //Parse into variable , convert from string to int
        int day1 = atoi(sDay.c_str());
        int month1 = atoi(sMonth.c_str());
        int year1 = atoi(sYear.c_str());
        int hour1 = atoi(sHH.c_str());
        int min1 = atoi(sMM.c_str());
        float s1; 
        int sr;
        // speed
        for (int i=0; i<10; i++)
        {
            input >> s1;
            input.ignore(100, ',');
        }
        //radiation
        for(int j =0; j<18; j++)
        {
            input >> sr;
            input.ignore(90,',');
        }
        // create a record
        T1.d.setDate(day1, month1, year1);
        T1.t.setTime(hour1, min1);
        T1.speed = s1;
        T1.solar = sr;
        windlog.push_back(T1);         
    }
}
windlog.print();
getMaxSpeed(2017,3);
return 0;
}

我试图根据用户输入的年度和月份获得最大速度。但是GetMaxSpeed(2017,3)的当前输出是:" 2017年度最大风速为:6.30584E-044'因此,我需要知道要过滤的适当语法是什么。 getMaximumValue方法

void getMaxSpeed(int y2, int m2)
{
 float maxSpeed;
 for (int i=0; i<windlog.size(); i++)
 {
    int y3 = windlog.at(i).d.getYear();
    int m3 = windlog.at(i).d.getMonth();
    if(y3==y2 && m3==m2){
    while(y3==y2 && m3==m2)
    {
        maxSpeed = windlog.at(0).speed;
        if (windlog.at(i).speed > maxSpeed)
        {
            maxSpeed = windlog.at(i).speed;
        }
     }
    }
  }
  cout<< maxSpeed << endl;
  }

一旦我找到了MaxSpeed,我就可以执行其余功能....

根据您提供的内容,您告诉ignore寻找逗号,但数据中没有任何逗号,因此它可以吃90或100个字符。如果将定界符更改为",则应获得想要的结果