Topic: to find all multiple entries in multimap
Author: "James Kuyper Jr." <kuyper@wizard.net>
Date: 1999/11/24 Raw View
Mabhin Ghosh Datta wrote:
>
> Hi!
> I am trying to get all multiple entries in a multimap. The "find"
> function only returns the first entry, "equal_range" gives the range. I
> don't want to iterate through each entry and do compare. Other way to
> copy the multimap, then delete the 1st element after "find" and then
> look for the second with "find" and so on. But I don't want to copy the
> multimap either. So what could be the way out?
> Any information in this regard will be highly appreciated.
> Thanks and regards.
Use upper_bound() to get an iterator for the first entry after a given
key. For keys with only a single entry, that will be equal to the
iterator for the first entry, incremented once.
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Mabhin Ghosh Datta <mghoshda@linmor.com>
Date: 1999/11/23 Raw View
Hi!
I am trying to get all multiple entries in a multimap. The "find"
function only returns the first entry, "equal_range" gives the range. I
don't want to iterate through each entry and do compare. Other way to
copy the multimap, then delete the 1st element after "find" and then
look for the second with "find" and so on. But I don't want to copy the
multimap either. So what could be the way out?
Any information in this regard will be highly appreciated.
Thanks and regards.
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Kurt" <kkurt@ifsx.net>
Date: 1999/11/23 Raw View
multimap<int, char> mm;
mm.insert( pair<int, char>(0, 'a')); mm.insert( pair<int, char>(0, 'b'));
mm.insert( pair<int, char>(0, 'c')); // insert three elements with key of 0
mm.insert( pair<int, char>(1, 'd')); mm.insert( pair<int, char>(1, 'e'));
mm.insert( pair<int, char>(1, 'f')); // insert three elements with key of 1
// find the entries with key of 0
pair<multimap<int, char>::iterator, multimap<int, char>::iterator > found
= mm.equal_range(0); .
// print them out
for(multimap<int, char>::iterator ii = found.first; ii != found.second;
ii++) {
cout << << (*ii).first << " = " << (*ii).second << endl;
}
Mabhin Ghosh Datta <mghoshda@linmor.com> wrote in message
news:383AEF62.DED34064@linmor.com...
>
> Hi!
> I am trying to get all multiple entries in a multimap. The "find"
> function only returns the first entry, "equal_range" gives the range. I
> don't want to iterate through each entry and do compare. Other way to
> copy the multimap, then delete the 1st element after "find" and then
> look for the second with "find" and so on. But I don't want to copy the
> multimap either. So what could be the way out?
> Any information in this regard will be highly appreciated.
> Thanks and regards.
>
>
>
> [ comp.std.c++ is moderated. To submit articles, try just posting with ]
> [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
>
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]