In this article we will discuss how to add element in a vector.

std::vector provides a member function to push an element at the end i.e.

It will push the element in the end of list. As, this function adds the element, so it also increases the size of vector by 1.

Check out following example of push_back with a vector of strings i.e.

Output:

The above code uses the c++11’s newly introduced for loop. To compile the above code use following command,

 

Python Recommendations:

C++ & C++11 Recommendations:

If you didn't find what you were looking, then do suggest us in the comments below. We will be more than happy to add that.

Subscribe with us to join 1500+ Python & C++ developers, to get more Tips &  Tutorials like this.