The unordered_multimap::size() is a built-in function in C++ Standard Template Library which return’s the number of element in the unordered map. Syntax:
unordered_multimap_name.size()
Return Value: It returns the number of the element present in the unordered map. Time complexity:
Constant i.e. O(1).
Program 1:
CPP
// C++ program to demonstrate // unordered_map size() method #include <iostream> #include <unordered_map> using namespace std;
int main()
{ unordered_map< char , char >
n{ { 'A' , 'G' },
{ 'B' , 'E' },
{ 'C' , 'E' },
{ 'D' , 'K' },
{ 'E' , 'S' } };
cout << "size of map = "
<< n.size() << endl;
return 0;
} |
Output:
size of map = 5
Program 2:
CPP
// C++ program to demonstrate // unordered_map size() method #include <iostream> #include <string> #include <unordered_map> using namespace std;
int main()
{ unordered_map<string, double > ra;
cout << "Initial size of map = "
<< ra.size() << endl;
ra = {
{ "Geeks", 1.556 },
{ "For", 2.567 },
{ "Geeks", 3.345 },
{ "GeeksForGeeks", 4.789 },
{ "GFG", 5.998 }
};
cout << "size of map = "
<< ra.size() << endl;
return 0;
} |
Output:
Initial size of map = 0 size of map = 4
Article Tags :