可视化如何做我遍历 std::map<std::string,shared_ptr<A>> 在 C++ 中的元素
visual how to do i iterate through elements of in std::map<std::string,shared_ptr<A>> in c++
如何比较 2 张地图的数据,例如
std::map<std::string,shared_ptr<A>>
其中 A 是struct
类型。我需要在数据类型序列化后进行比较。
例如。
struct A
{
int age;
std::string name;
}
谢谢
要遍历映射,请使用迭代器:
typedef std::map<std::string, shared_ptr<A> > Container_Type;
Container_Type my_map;
Container_Type::iterator iter;
for (iter = my_map.begin(); iter != my_map.end(); ++iter)
(
// Do stuff here
}
可通过以下方式访问地图的字段:
std::string key;
key = iter->first;
shared_ptr<A> value = iter->second;
相关文章:
- 使用std::multimap迭代器创建std::list
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- 从持续时间构造std::chrono::system_clock::time_point
- std::具有相同基类的类的变体
- std::向量与传递值的动态数组
- 使用std::vector的OpenCL矩阵乘法
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- std::condition_variable::wait()如何评估给定的谓词
- 如何获取std::result_of函数的返回类型
- std::原子加载和存储都需要吗
- 将对象移动到std::shared_ptr
- std::vector<;uint8_t>;当C++11/14启用时,手动复制而不是调用memcpy
- 是std :: set&lt; std :: future&gt;不可能存在
- 在修改列表后,std :: list&lt; t&gt; :: end()的值是否会更改
- 使用 std::vector<boost::shared_ptr<Base_Class>> 或 boost::p tr_vector 的性能注意事项是什么<Base>
- std::map<std::set, double> AND std:<long>map< std::p air<long, long>, double>
- 如何获取std::vector<DMatch>