I have a map:
typedef map<string, float> my_map;
my_map maxmap;
I’m trying to find the maximum float value and its corresponding string key. This is how I’m finding the max float value but I get a segmentation fault and also don’t know how to find the corresponding string key.
float max = *(max_element(&(maxmap.begin()->second), &(maxmap.end()->second)));
Thanks a lot!!
maxmap.end()->second<– What your trying to do here is dereference the end iterator which is not valid.Just use a for loop: