C++ vector push_back() function
Example
Add an element at the end of a vector:
vector<string> cars = {"Volvo", "BMW", "Ford", "Mazda"};
cars.push_back("Toyota");
for (string car : cars) {
cout << car << "\n";
}
Try it Yourself »
Definition and Usage
The push_back() function adds an element to the end of a vector.
Syntax
vector.push_back( <type> value );
<type> refers to the type of the data that the vector contains.
Parameter Values
| Parameter | Description |
|---|---|
| value | Required. The value of the element being added. |
Related Pages
Read more about vectors in our Vector Tutorial.