如何获取地图中向量的第二个值?
How to get the second value of a vector that is in a map?
我的 c++ 中有这段代码
map<int,vector< pair <vector<int>,int> > > m;
我想获得第一个向量中的int
,因此我尝试了这段代码。
m[y].second;
但是我得到了这个错误:
No member named 'second' in 'std::__1::vector<std::__1::pair<std::__1::vector<int, std::__1::allocator<int> >, int>,
std::__1::allocator<std::__1::pair<std::__1::vector<int, std::__1::allocator<int> >, int> > >'
通过m[y]
,我希望得到向量,通过.second
我希望得到整数,那么问题是什么?
到
m[y]
年,我希望得到vector
没错,您可以从m[y]
表达式中获得对vector<pair<vector<int>,int>>
的引用
通过
.second
我希望得到整数
不,vector<pair<vector<int>,int>>
没有.second
成员。您还需要一次取消引用,要么
m[y][0].second
或
m.at(y).front().second
相关文章:
- 对的排序向量 (std::vector<pair<int, int>>) 按对的第一个元素搜索并更新第二个元素值
- 比较 2 个向量并从第二个向量中删除在第一个 - c++ 中找不到的元素
- c++:交换向量中所有元组的第一个和第二个元素
- C++ - 同时对向量的第一个和第二个进行排序
- 为什么我在对向量的第二个元素"push_back"中有C3867错误
- 如何有效地用第二个值对向量对进行分组
- 使用索引与迭代器将向量迭代到倒数第二个元素
- 将对象方法从向量应用于C 的第二个向量中的对象
- 如何在C 对向量的第二个元素上执行较低的操作
- 如何获取地图中向量的第二个值?
- 迭代对向量并访问第一个和第二个元素
- 将出现在此值之前的向量中的第二个值相加<pair>
- 向量C ,获取向量的第二个元素有什么问题
- 在C++中,如何在成对向量的第二个元素上获得迭代器
- 在 c++ 中给出两个整数向量(大小和类型相同),我想从最小到最大元素对一个进行排序,并更改第二个向量的顺序
- 分割 使用指针访问 obj 向量中的第二个元素时出错
- 如何在C++中找到向量中倒数第二个元素
- 如何基于第二个字符串对字符串向量的向量排序
- 遍历以向量和映射作为其第二个节点的映射,并在第二个节点的第二个元素中找到匹配项。C++
- 如何从一对向量中提取第二个元素