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