English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
This function adds a new element at the end of the vector (vector).
Vector (vector) v, 'k' is the value. The syntax is:
v.push_back(k)
k: k is the value to be inserted at the end of the vector (vector).
This function does not return any value.
The following figure shows how the push_back() function works:
This figure illustrates the insertion of a new element at the end using the push_back() function.
Let's look at a simple example.
#include<iostream> #include<vector> using namespace std; int main() { vector<char> v; v.push_back('j'); v.push_back('a'); v.push_back('v'); v.push_back('a'); for(int i = 0; i < v.size(); i++) cout << v[i]; return 0; }
Output:
java
In this example, the push_back() function inserts the new element into the vector v.