unordered_map count() in C++ Last Updated : 26 Sep, 2018 Comments Improve Suggest changes Like Article Like Report The unordered_map::count() is a builtin method in C++ which is used to count the number of elements present in an unordered_map with a given key. Note: As unordered_map does not allow to store elements with duplicate keys, so the count() function basically checks if there exists an element in the unordered_map with a given key or not. Syntax: size_type count(Key); Parameters: This function accepts a single parameter key which is needed to be checked in the given unordered_map container. Return Value: This function returns 1 if there exists a value in the map with the given key, otherwise it returns 0. Below programs illustrate the unordered_map::count() function: Program 1: CPP // C++ program to illustrate the // unordered_map::count() function #include<iostream> #include<unordered_map> using namespace std; int main() { // unordered map unordered_map<int , string> umap; // Inserting elements into the map umap.insert(make_pair(1,"Welcome")); umap.insert(make_pair(2,"to")); umap.insert(make_pair(3,"GeeksforGeeks")); // Check if element with key 1 is present using // count() function if(umap.count(1)) { cout<<"Element Found"<<endl; } else { cout<<"Element Not Found"<<endl; } return 0; } Output: Element Found Program 2: CPP // C++ program to illustrate the // unordered_map::count() function #include<iostream> #include<unordered_map> using namespace std; int main() { // unordered map unordered_map<int , string> umap; // Inserting elements into the map umap.insert(make_pair(1,"Welcome")); umap.insert(make_pair(2,"to")); umap.insert(make_pair(3,"GeeksforGeeks")); // Try inserting element with // duplicate keys umap.insert(make_pair(3,"CS Portal")); // Print the count of values with key 3 // to check if duplicate values are stored // or not cout<<"Count of elements in map, mapped with key 3: " <<umap.count(3); return 0; } Output: Count of elements in map, mapped with key 3: 1 Comment More infoAdvertise with us Next Article unordered_map count() in C++ S Sektor_jr Follow Improve Article Tags : C++ Practice Tags : CPP Similar Reads unordered_map at() in C++ In C++, unordered_map at() is a library function used to find the value associated with a given key in the unordered_map container. Let's look at an example to see how to use this function.C++#include <bits/stdc++.h> using namespace std; int main() { unordered_map<int, string> um = {{1, 2 min read unordered_map cend in C++ STL The unordered_map::cend() is a built-in function in C++ STL which returns an iterator pointing to the position past the end element in the container or in one of its bucket. In an unordered_map object, there is no guarantee that which specific element is considered its first element. But all the ele 3 min read unordered_map begin() in C++ The unordered_map::begin() is a built-in function in C++ STL which returns an iterator pointing to the first element in the unordered_map container or in any of its bucket. Syntax for first element in unordered_map container: unordered_map.begin() Parameters: This function does not accepts any param 2 min read unordered_map cbegin in C++ STL cbegin function in c++ is used to return a constant iterator pointing the first element in an unordered map. Syntax: unordered_map.cbegin() Parameter: It takes an optional parameter N. If set, the iterator returned will point to the first element of the bucket otherwise it point to the first element 2 min read unordered_map find in C++ STL In C++, std::unordered_map::find function is used to search for a specific element using the key in an unordered map container. It is a member function of std::unordered_map container defined inside <unordered_map> header file.Syntaxum.find(key);Parameterskey: The key of the element to be sear 1 min read Like