473,387 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Multimap & iterator.

7
I want to give an array the values from the specific multimap's key's values.
Expand|Select|Wrap|Line Numbers
  1. multimap<string,int> mymultimap;
  2. multimap<string,int>::iterator it;
  3. pair<multimap<string,int>::iterator,multimap<string,int>::iterator> ret;
  4.  
  5. mymultimap.insert (pair<string,int>("test",10));
  6. mymultimap.insert (pair<string,int>("test",20));
  7. mymultimap.insert (pair<string,int>("ab",100));
  8. mymultimap.insert (pair<string,int>("ab",200));
  9.  
  10. int arr[2];
  11.  
  12. ret = mymultimap.equal_range("test");
  13. for (it=ret.first; it!=ret.second; ++it){
  14.     arr[it] = (*it).second; //arr[it] results in an error.
  15. }
  16.  
With this code I want the array 'arr' to have the same values as 'mymultimap's "test" values, which is: 10 and 20. But as the iterator 'it' isn't an int/char etc. it can't be assorted with the array 'arr'
Oct 21 '07 #1
1 2685
Laharl
849 Expert 512MB
You can use a while loop and a count variable.

Expand|Select|Wrap|Line Numbers
  1. int count;
  2. while (it != ret.end()){
  3.     arr[count] = (*i).second;
  4.     count++;
  5. }
  6.  
You can use a for loop, but it feels a little redundant in this case.
Oct 21 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Tanguy Fautré | last post by:
Hello, does std::multimap make any guarantee about the insertion order? for example: int main() { std::multimap<int, int> Map;
9
by: Dennis Jones | last post by:
Hi, Is there a way to iterate through a multimap in such a way as to encounter only the unique keys? In other words, since a multimap allows duplicate keys, I would like to iterate through the...
3
by: Przemek | last post by:
All, what is the efficient way to find all distinct keys in a multimap. I use the code template<class T1, class T2> set<T1> GetDistinctKeys(multimap<T1, T2> nMap) { T1 temp; multimap<T1,...
4
by: Nick Keighley | last post by:
Hi, I've checked out various documentation for multimap but can't find anywhere it explicitly stated that insert() invalidates multimap iterators. consider this pseudo code:- int...
3
by: giuseppe.cannella | last post by:
i must create a muiltimap with 2 string , 1 int and 1 iterator to multimap itself how could define the typedef? thank
4
by: sks | last post by:
I have a question regarding std::multimap/iterators. At the SGI website, it says "Erasing an element from a multimap also does not invalidate any iterators, except, of course, for iterators that...
1
by: ambarish.mitra | last post by:
Hi all, I have a multimap, where key is an int and the value is a class. I can insert into the multimap, but finding it difficult to retrieve the value when keys match. I can do this with...
20
by: puzzlecracker | last post by:
I am using while loop for that but I am sure you can do it quicker and more syntactically clear with copy function. Here is what I do and would like to if someone has a cleaner solution: ...
7
by: Moschops | last post by:
In moving some code from VS6 to VS2008 (bear with me, this is not a VS question, I'm just setting context), we find new crashes that weren't there before and we think they're related to trying an...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.