作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我有3个都具有相同键的多图(在这种情况下,这是日期),并且它们代表的值对于每个图都是不同的。我知道如何创建迭代器并在一个 map 上进行迭代,然后使用该迭代器获取该 map 的值。但是,我将如何遍历所有3个映射并将它们的值放入所需的变量中?我很困惑,因为如果我使用一个迭代器来遍历所有3个映射,那么该迭代器只会为我提供为其创建迭代器的映射的值,而且我觉得为此创建3个for循环会有点麻烦。有任何想法吗?
multimap<Date, float> mapOption4WindSpeed;
multimap<Date, float> mapOption4Temperature;
multimap<Date, double> mapOption4Solar;
cout << "Please enter year (xxxx): " << endl;
cin >> year;
Date newDate;
newDate.SetDay("1");
newDate.SetDay("1");
newDate.SetDay(year);
for(int i = 0; i < SIZE; i++)
{
mapOption4WindSpeed.insert(make_pair(windlog[i].d, windlog[i].speed.GetSpeed()));
mapOption4WindSpeed.insert(make_pair(windlog[i].d, windlog[i].temp.GetTemperature()));
mapOption4Solar.insert(make_pair(windlog[i].d, windlog[i].solar.GetSolar()));
}
multimap<Date, float>::iterator itS = mapOption4WindSpeed.find(newDate);
multimap<Date, float>::iterator itT = mapOption4Temperature.find(newDate);
multimap<Date, double>::iterator itSol = mapOption4Solar.find(newDate);
for(int i = 0; i < SIZE; i++) //Loop through entire array to check if the input matches the year
{
if(itS != mapOption4WindSpeed.end()) //This statement and the above is where I am confused
{
//Bunch of operations in here
}
typedef struct
{
Date d;
Time t;
Weather speed;
Weather solar;
Weather temp;
} WindLogType;
Vector<WindLogType> windlog;
最佳答案
so I have 3 multimaps that all have the same keys (Which in this case are Dates), and the values they represent are different for each map.
multimap
,否则我建议您创建一个
multimap
。
struct MyData
{
float windSpeed;
float temperature;
double solar;
};
std::multimap<Date, MyData> mapOfMyData;
Date
对应的所有数据变得容易。
关于c++ - 如何遍历多个 map 并获取其值? -C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62275203/
我是一名优秀的程序员,十分优秀!