The multimap::count is a built-in function in C++ STL which returns the number of times a key is present in the multimap container.
Syntax:
multimap_name.count(key)
Parameters: The function accepts one mandatory parameter key which specifies the key whose count in multimap container is to be returned.
Return Value: The function returns the number of times a key is present in the multimap container.
#include <bits/stdc++.h>
using namespace std;
int main()
{
multimap< int , int > mp;
mp.insert({ 2, 30 });
mp.insert({ 1, 40 });
mp.insert({ 2, 60 });
mp.insert({ 2, 20 });
mp.insert({ 1, 50 });
mp.insert({ 4, 50 });
cout << "1 exists " << mp.count(1)
<< " times in the multimap\n" ;
cout << "2 exists " << mp.count(2)
<< " times in the multimap\n" ;
return 0;
}
|
Output:
1 exists 2 times in the multimap
2 exists 3 times in the multimap
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
18 Nov, 2020
Like Article
Save Article