从单键多值容器访问特定值
Accessing specific value from single key-multiple value containers
我正在尝试使用C++实现多值容器,并自由访问其中的每个值。我有整数键;X、Y、宽度、高度等值作为输入。
我正在尝试从每个键中提取值。但显然,代码在这种情况下不起作用。
我想得到一些建议,是否可以做到这一点,或者任何预定义的容器库在访问多个值方面具有更好的灵活性。
我尝试了独立的单键、单值"多映射"容器,但它消耗了太多内存空间和拖拽性能
multimap<int, multimap <multimap<int, int>, multimap<int, int>>> BlobPos = {};
//[<1,{(2,3),(4,5)}>,<2,{(6,7),(8,9)}>
for (auto it = BlobPos.begin();it != BlobPos.end(); it++) {
auto X = it->second-> first->first;
auto Y = it->second->first->second;
auto H = it->second->second->first;
auto W = it->second-second->second;
cout << X << Y << H << W;
2 3 4 5
6 7 8 9
下面是一个结构几乎如您的问题中所述的容器的示例:
#include <map>
#include <utility>
#include <iostream>
int main() {
std::map<int, std::pair<std::pair<int, int>, std::pair<int, int>>> BlobPos = {{1, {{2, 3}, {4, 5}}}, {2, {{6, 7}, {8, 9}}}};
for (auto it = BlobPos.begin();it != BlobPos.end(); it++) {
auto X = it->second.first.first;
auto Y = it->second.first.second;
auto H = it->second.second.first;
auto W = it->second.second.second;
std::cout << X << Y << H << W << 'n';
}
return 0;
}
引用需要运算符->
但下一级使用运算符.
来访问元素。
相关文章:
- 访问单例类C++时出现问题
- 使用 ofstream 迭代访问和写入多个文件
- 从单键多值容器访问特定值
- 提升property_tree:模板类上每个键多个值
- 如何在OpenCV中访问单通道矩阵
- 访问冲突.C++多态性
- 单读多写器,带pthreads和锁,不带boost
- 无法访问存储在多维向量中的对象 (C++)
- 无锁单写多读列表的实现细节
- 可以处理随机访问和键搜索的数据结构是什么?
- 使用共享指针访问单例子类时的SEGFAULT
- 全局访问单例数据
- 我们是否需要互斥锁来访问 C++11 - 多线程中单例对象中的数据字段
- JNI保留对对象的全局引用,并使用其他JNI方法访问它.在多个JNI调用中保持C++对象的活动状态
- 跨平台C++代码和单头-多个实现
- 如何在Opencv中访问单通道IplImage的元素
- Qt同时单击多个鼠标
- 是否不希望将指针存储在具有不同访问方法的多个容器中?
- Qt:如何同步访问数据从多个线程在模型/视图设置
- 访问unique_ptr的多维向量中持有的对象的方法