Click here to Skip to main content
15,885,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am storing key-value pair in Multimap (I have duplicate keys and values, so I'm using multimap).
I need to iterate every key and corresponding key's value, then return the value if both key and value match the condition. How can I achieve this using multimap?

Example:

Key - Value
a - Red
b - Green
c - Red
a - Blue

From this above key-value pair, I need to return above value for the corresponding key if both key and value match the condition.

I need to do like this,

MyKey = a
MyValue = Blue

if(MyKey==Key && MyValue==Value )
{
// Return map value.
}

What I have tried:

I need to do like this,

MyKey = a
MyValue = Blue

if(MyKey==Key && MyValue==Value )
{
// Return map value.
}
Posted
Updated 21-Aug-19 21:38pm

1 solution

Use the multimap Class find method[^] to find the first element with the matching key. You can then use the iterator to check each matching entry for the required value.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900