YetiCodeCamp - C++ for Beginners

Companion website for the C++ for Beginners YouTube video series.

C++ Vector push_back() Function

The C++ vector.push_back() function adds a new element at the end of a vector. This function takes a single parameter which is the value to be inserted at the end of the vector.


Example, using a vector “v1”, and a value to be inserted of “99”.


Adds a new element with a value of “99” to the end of the vector.

This example is a complete program using the vector push_back() function to add a new element to the end of a vector.


int main()
std::vector<int> numbers{1,2,3,4,5,6};

for( v : numbers)
    std::cout << v << " ";

return 0;

Output: 1 2 3 4 5 6 99