我有一个元素的映射表,我想要遍历这个映射表。当然,标准的方法是使用for循环。
for (map<string, int> iterator it = myMap.begin(); it != myMap.end(); ++it) {
string thisKey = it->first;
int thisValue = it->second;
}
但是,如果我尝试使用 OpenMP 的 parallel for 构造使这个循环并行运行,它就不起作用,并且这是(显然)一个已知的问题,因为它不识别这种类型的循环构造。
因此,我的备选方案是使用整数索引迭代器,并通过索引访问键和值列表,就像在 C# 中所做的那样:
for (int i = 0; i < myMap.Count; ++i) {
string thisKey = myMap.Keys[i];
string thisValue = myMap.Values[i];
}
...但我似乎找不到C++中对应的方法。在C++中有没有我不知道的方法可以实现这个?
std::map
是实现您想要的功能的最佳容器吗? - AJG85