可视化如何做我遍历 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++

本文关键字:std gt lt C++ 元素 ptr string 遍历 何做我 map 可视化      更新时间:2023-10-16

如何比较 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;