【发布时间】:2016-05-11 04:53:41
【问题描述】:
我在访问矢量容器中的地图和配对成员时遇到问题。我尝试使用 for 循环和向量迭代器来尝试访问向量内的元素,但没有运气。这是我的代码:
typedef int lep_index;
typedef double gold;
typedef double pos;
map<lep_index, pair<gold, pos>> lep;
vector <map<lep_index, pair<gold, pos>>> leps;
//initialize lep and leps
for (int i = 1; i <= 10; i++) {
lep[i - 1] = pair<gold, pos>(MILLION, i * MILLION);
leps.push_back(lep);
}
//I can access lep's elements by doing this
for (auto &i : lep) {
cout << i.first << ": " << i.second.first << ", " << i.second.second << endl;
}
//but when i try with vector...
for (vector <map<lep_index, pair<gold, pos>>>::iterator it = leps.begin(); it != leps.end; it++) {
cout << it->
}
//I cannot use it pointer to access anything
我不知道我在这里做错了什么或正确的方法,所以希望我能得到一些帮助。
【问题讨论】:
标签: c++ dictionary vector std-pair