C++ Vector pop_back
It deletes the last element and reduces the size of the vector by one.
Syntax
Consider a vector v.Syntax would be:
Example
v.pop_back();
Parameter
It does not contain any parameter.
Return value
It does not return any value.
The following illustration show how pop_back function works :
This illustration shows how last element of the vector is deleted using pop_back function.
Example
Let's see a simple example.
Example
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<string> v{"welcome","to","javaCppTutorial","tutorial"};
cout<<"Initial string is :";
for(inti=0;i<v.size();i++)
cout<<v[i]<<" ";
cout<<'\n';
cout<<"After deleting last string, string is :";
v.pop_back();
for(int i=0;i<v.size();i++)
cout<<v[i]<<" ";
return 0;
}
Output:
Output
Initial string is :welcome to javaCppTutorial tutorial
After deleting last string, string is :welcome to javaCppTutorial
In this example, last string is being removed using pop_back function.