0

Hello all, is there simple way to check if a multimap contains a value, or am I going to have to loop through all pairs?
thanks

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by sciwizeh
1

Is this what you're looking for?

#include <iostream>
#include <map>


int main(int argc, char *argv[])
{
	
	std::multimap <int, double> MyMap;
	
	//create a mapping from "testone" to 111
	MyMap.insert(std::pair<int, double>(1, 1.2));
	
	//create an iterator
	std::map<int, double>::iterator iter;

	iter = MyMap.find(1);
	
    if(iter == MyMap.end())
    {
      std::cout << "Not found." << std::endl;
    }
    else
    {
	std::cout << "Found: " << iter->second << std::endl;	
    }
    
	return 0;
}

Dave

Votes + Comments
Just the info I needed
0

Yes, thank you, that is what I was looking for. It's strange, the documentation I was reading said that find looked for the value, but the example showed that it would search for the key, so I was slightly unsure.

solved, thanks

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.