473,569 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multimap & iterator.

7 New Member
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 2702
Laharl
849 Recognized Expert Contributor
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
13434
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
7855
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 entire multimap, and if a particular key has duplicates, only see one of them. I don't think I care about which of the duplicate entries I see,...
3
6064
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, T2>::iterator i_ptr;
4
4492
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 DataItem::genDerived () {
3
2954
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
4222
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 actually point to the element that is being erased." I design/implemented a observer pattern that is priority based. It so happened that...
1
2220
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 primitive types (int/char etc). Example: class A {
20
3959
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: vector<stringvec; multimap<stirng, intmyMap // populate myMap
7
2311
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 operation on a multimap that is empty - for example, std::multimap<double, aStructWeHaveDefined>::iterator low; low = c.begin() ; // c is empty...
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7926
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7679
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6287
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.