Search code examples
c++iteratorcharstdmap

How to access C++ map inner values


This is my map std::map<std::string,ProductInfo> mymap and these are the values inside ProductInfo:

bool isActive = false;
char name[80];

I am already able to access a specific key - value pair (std::string - ProductInfo) using ::iterator but what I actually need is the name property inside ProductInfo

also this is what ProductInfo looks like during debug


Solution

  • You want to access the property name of the ProductInfo object inside a map. What you need to do is your_map["the key"]->get_name() where get_name() is a getter for name in ProductInfo.