我已创建的形式的两个映射:合并两个地图C++
[事件号] [质量]称为地图results_JMass
和
[事件号] [动量]称为地图results_PhotonPt
两个图都有相同的键(事件号),它是一个整数并且包含双精度值。我想创建形式的第三张地图:
[事件数] [质量] [势头]
我知道我需要使用
std::map <Int_t, std::vector< pair <Double_t,Double_t> > > new_map;
但我不知道如何将两张地图结合起来创造出第三张。
这是我想出了:
for (auto& kv3 : results_JMass) { //Iterates the data with kv3 as the iterator and the results_jMass what kv3 is iterating through
event_number = kv3.first; //Iterator for the first index, i.e the events
m = kv3.second; //iterator for the second index i.e the masses
new_map [event_number].first = m;
for (auto&kv4: results_PhotonPt) {
event_number = kv4.first;
p = kv4.second;
new_map [event_number].second = p;
}
}
,保证包含相同的事件号的两个地图? – Steve
与您的问题无关,但“Int_t”和“Double_t”是什么?他们是普通的'int'还是'double'?为什么使用自定义类型名称? –
在我看来,表达地图的正确方法应该是:'std :: map> new_map;' –
Amadeus