Web_Sailor 0 Junior Poster

Hi :)
I was trying to find the max length in my multimap.
here is how I define it:

multimap<int, string> mm;
multimap<int,string>::iterator it;

mm.insert(pair<int, string>(some_int, myvalues));

Now the main part that I want to discuss is this. I have created 2 functions to find the size of records in my multimap. These functions work fine for me when I use

multimap<string, string>

but when I use int type they give me compile time erros:-
Something like below

error: request for member ‘size’ in ‘i.std::pair<int, int>::first’, which is of non-class type ‘int’

Can somebody tell me how to make it work for multimap<int, string> type also ? :-/

Below are my functions for maxlength finding. Fisrst one is faultty and the 2nd one works:-

bool maxlengthfirst(std::pair<int, int> i,std::pair<int, int> j){ 

              return i.first.size()<j.first.size();

  }



  bool maxlengthsecond(pair<string,string> i,pair<string,string> j){ 

              return i.second.size()<j.second.size();

  }

Ultimately I want to use it like this and it works for <string,string> type of multimap:

for (it=(mm.begin()); it!=(mm.end()); it++)

          {

               cout.width(secondSize);

               cout.fill('0');              

               cout << it->first <<"\t";

               cout.width(firstSize);

               cout.fill(' ');

               cout << it->second << endl;

          } 

  mm.clear();
}

Thanks :icon_razz:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.