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