Click here to Skip to main content
14,297,338 members
Rate this:
Please Sign up or sign in to vote.
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100