multimap::count() in C++ STL
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.
// C++ function for illustration // multiset::count() function #include <bits/stdc++.h> using namespace std; int main() { // initialize container multimap<int, int> mp; // insert elements in random order mp.insert({ 2, 30 }); mp.insert({ 1, 40 }); mp.insert({ 2, 60 }); mp.insert({ 2, 20 }); mp.insert({ 1, 50 }); mp.insert({ 4, 50 }); // count the number of times // 1 is there in the multimap cout << "1 exists " << mp.count(1) << " times in the multimap\n"; // count the number of times // 2 is there in the multimap cout << "2 exists " << mp.count(2) << " times in the multimap\n"; return 0; } |
chevron_right
filter_none
Output:
1 exists 2 times in the multimap 2 exists 3 times in the multimap
Recommended Posts:
- Structures in C++
- Variables in C++
- Implementing Forward Iterator in BST
- Count substrings that contain all vowels | SET 2
- Machine Learning in C++
- How can we use Comma operator in place of curly braces?
- Optimally accommodate 0s and 1s from a Binary String into K buckets
- Remove first adjacent pairs of similar characters until possible
- Find a number containing N - 1 set bits at even positions from the right
- Sort an array according to absolute difference with given value using Functors
- Rearrange characters in a string such that no two adjacent are same using hashing
- Remove duplicate elements in an Array using STL in C++
- r-Nearest neighbors
- Increment (++) and Decrement (--) operator overloading in C++
- std::uniform_int_distribution max() method in C++ with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



