C++ unordered_set size() Function
Example
Get the number of elements in an unordered set:
unordered_set<string> cars = {"Volvo", "BMW", "Ford", "Mazda"};
cout << cars.size();
Definition and Usage
The size() function returns the number of elements in an unordered set.
The size function is defined in the <unordered_set> header file.
Tip: Use empty() to check if an unordered set has no elements.
Syntax
unordered_set.size()
Parameter Values
None.
Technical Details
| Returns: | The number of elements in the unordered set (a non-negative integer). |
|---|
Related Pages
Read more about unordered sets in our Unordered Set Tutorial.