C++ unordered_map size() Function
Example
Get the number of elements in an unordered map:
unordered_map<string, int> people = {{"John", 32}, {"Adele", 45}, {"Bo", 29}};
cout << people.size();
Definition and Usage
The size() function returns the number of elements in an unordered map.
The size function is defined in the <unordered_map> header file.
Tip: Use empty() to check if an unordered map has no elements.
Syntax
unordered_map.size()
Parameter Values
None.
Technical Details
| Returns: | The number of elements in the unordered map (a non-negative integer). |
|---|
Related Pages
Read more about unordered maps in our Unordered Map Tutorial.