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

  • SEARCH
  • Home
  • 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 9018519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:32:51+00:00 2026-06-16T04:32:51+00:00

The multimap contains multimap<int,Questions*> map; . Im trying to get the map printing out

  • 0

The multimap contains multimap<int,Questions*> map;. Im trying to get the map printing out using the following method:

Questions* Questions::printQuestion(int level)
{
    multimap<int, Questions*>::iterator it;
    pair<multimap<int, Questions*>::iterator,multimap<int, Questions*>::iterator> ret;

    ret = map.equal_range(level);
    if(ret.first != ret.second)
    {
    size_t sz = distance(ret.first, ret.second);
    size_t idx = rand() % sz;
    advance(ret.first, idx);
    it =ret.first;
    return (*it).second;
    }
    else
    {
        return NULL;
    }
}

But the method does nothing. Can anybody help me with this?

  • 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-16T04:32:52+00:00Added an answer on June 16, 2026 at 4:32 am

    This function doesn’t print anything. It returns a Questions* that is randomly chosen from all questions with the given level. So if there are three questions with level 5, and you call printQuestion(5), you will get a pointer to a random question of those three. If you want to print the question that is chosen in this function, you will have to do something like so:

    Questions* question = (*it).second;
    std::cout << question->getText() << std::endl;
    

    Replace getText() with whatever you need to do to print the question.

    If you want the client that calls the function to print the question, you’ll do:

    Questions* question = printQuestion(5);
    std::cout << question->getText() << std::endl;
    

    By the way, it’s not very common to name classes with the plural form. It’ll be easier to read your code if you class is called Question instead of Questions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a std::multimap on which I am iterating using a forward iterator. std::multimap<int,char>::iterator
If I have a map/multimap with keys inserted using a comparison function (functor), is
if I'm using the Scala Multimap, and I want to get the values associated
Using a multimap like below: multimap<int, string> mm; mm.insert(make_pair(1, jack)); mm.insert(make_pair(1, jack)); mm.insert(make_pair(1, jack));
I'm trying to figure out how std::multimap iterators work, therefore I've created a simple
I have a map using the multimap trait, like so val multiMap = new
i'm using a multimap stl, i iterate my map and i did'nt find the
I'm using a mutable HashMap with the MultiMap mixin and noticed that the map.add
Hey im trying to print out my multimap values but im getting an error
I'm using MultiMap from Google Guava 12 like this: Multimap<Integer, OccupancyType> pkgPOP = HashMultimap.create();

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.