A C++ container type called std::map is used to store elements that are formed by a combination of key value and mapped value. How do you iterate through this container and find the value mapped to a specific key?
std::map<std::string,std::string> x;
x["test"] = "a";
x["2"] = "c";
// Enumerate all keys/values
for(auto it : x)
{
std::cout << it->first << " : " << it->second << std::endl;
}
// Find a specific key
auto it = x.find("test");
if(it != x.end())
std::cout << it->second << std::endl;
// Print an element (Element will be added if not present)
std::cout << x["2"];
You would iterate through it using its iterators and access members using the [] operator. You can also use the find method to check if an key is within the map. For more info please goto http://www.cplusplus.com/reference/map/map/