C 从没有STL的用户输入中获得CSVWITH的最大值
C++ Getting maximum value from CSVwith year and month from user input without STL
我试图从 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个字符。如果将定界符更改为",则应获得想要的结果
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- 使用指针从C++中的数组中获取最大值
- 如何将这个C++哈希表转换为动态扩展和收缩,而不是使用硬设置的最大值
- 如何创建一个函数来计算并返回平均值、最大值和最小值
- 在二维数组中查找最小值和最大值?
- 整数溢出,最大值为 pow(10,19)
- 以C++递归方式查找向量中的最大值
- C++ - 如何在结构向量中找到结构体一个成员的最大值?
- 查找数组中第一个最小值和最后一个最大值元素之间的算术平均值
- C++ 函数,用于查找传入的 N 个数字的平均值、总和、最小值和最大值
- 我的 If Else 语句无法在向量 (C++) 中提供最大值
- 如何使用可变参数模板类使用模板元编程获得最大值
- C++不同的最小最大值实现
- Vec3b:r/g/b 颜色的最大值为 254,而不是 255
- CUDA - 将 float3 数组的 (x,y,z) 分量的最小值/最大值分开?
- 是否可以将无符号 int 的最大值转换为 int 并将结果转换为 -1?
- 查找包含 N 个元素的数组的最小值和最大值
- 井字游戏具有奇怪行为的最小最大值算法(C++)
- 错误C++在Visual Studio 2019中使用numeric_limits的长双精度最小值/最大值
- C 从没有STL的用户输入中获得CSVWITH的最大值