C++ list push_back() Function
Example
Add an element at the end of a list:
list<string> cars = {"Volvo", "BMW", "Ford", "Mazda"};
cars.push_back("Toyota");
for (string car : cars) {
cout << car << "\n";
}
Definition and Usage
The push_back() function adds an element to the end of a list.
The push_back function is defined in the <list> header file.
Syntax
list.push_back(<type> value);
<type> refers to the type of the data that the list contains.
Parameter Values
| Parameter | Description |
|---|---|
| value | Required. The value of the element to add. |
Technical Details
| Returns: | Nothing (void). |
|---|
Related Pages
Read more about lists in our List Tutorial.