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