[英]how to do i iterate through elements of in std::map<std::string,shared_ptr<A>> in c++
how to compare data of 2 maps like 如何比较2个地图的数据,例如
std::map<std::string,shared_ptr<A>>
where A is struct
type. std::map<std::string,shared_ptr<A>>
其中A是struct
类型。 I need to compare after the serialization of data type. 数据类型序列化后,我需要进行比较。
eg. 例如。
struct A
{
int age;
std::string name;
}
thanks 谢谢
To iterate through a map, use an iterator : 要遍历地图,请使用迭代器 :
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
}
The fields of the map can be accessed by: 可以通过以下方式访问地图的字段:
std::string key;
key = iter->first;
shared_ptr<A> value = iter->second;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.