C++ Vector push_back
This function appends a new item to the vector.
Syntax
Consider a vector v and let 'k' represent the value. The syntax would be:
v.push_back(k)
Parameter
k : k represents the specific value that will be added to the vector at its conclusion.
Return value
This function does not return any value.
The upcoming diagram demonstrates the functionality of the push_back method:
This diagram demonstrates that the push_back method adds a new element at the back.
Example
Let's see 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:
In this instance, the push_back method adds the additional elements to the vector v.