C++ list front() Function
Example
Get the first element of a list:
list<string> cars = {"Volvo", "BMW", "Ford", "Mazda"};
cout << cars.front();
Definition and Usage
The front() function returns the first element of a list.
You can also use it to change the first element, like cars.front() = "Opel";.
The front function is defined in the <list> header file.
Syntax
list.front();
Parameter Values
None.
Technical Details
| Returns: | A reference to the first element of the list. |
|---|
Related Pages
Read more about lists in our List Tutorial.