Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8734885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:56:01+00:00 2026-06-13T09:56:01+00:00

I have a map: typedef map<string, float> my_map; my_map maxmap; I’m trying to find

  • 0

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!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:56:01+00:00Added an answer on June 13, 2026 at 9:56 am

    maxmap.end()->second <– What your trying to do here is dereference the end iterator which is not valid.

    Just use a for loop:

    typedef my_map::iterator iter;
    iter it = maxmap.begin();
    iter end = maxmap.end();
    
    float max_value = it->second;
    std::string str = it->first;
    for( ; it != end; ++it) {
        if(*it->second > max_value) {
            max_value = it->second;
            str = it->first;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pair and a map declared as such typedef pair<string,string> Key; typedef
I'm trying to do this: typedef std::map<std::string, time_t> my_map; const mymap& some_function(); class bla
Let's say I have two maps: typedef int Id; std::map<Id, std::string> idToStringMap; std::map<Id, double>
In my current setup, I have a typedef std::function<void (MyClass&, std::vector<std::string>) MyFunction; std::map<std::string, MyFunction>
I have a map named valueMap as follows: typedef std::map<std::string, std::string>MAP; MAP valueMap; ...
So I have such function: boost::shared_ptr<my_class> get_class_by_name(std::string name) { typedef std::map<boost::shared_ptr<my_class>, my_description> map_t; BOOST_FOREACH(map_t::value_type
I have a vector of maps: typedef map<string, string> aMap; typedef vector<aMap> rVec; rVec
This is kind of last resort.. So I have two maps. typedef std::map <string,
Basically I have, typedef map<std::string, set<double> > MAP_STRING_TO_SET; What is the best way to
I have code like this: class MapIndex { private: typedef std::map<std::string, MapIndex*> Container; Container

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.