English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
It deletes the last element and reduces the size of the vector (vector) by one.
Vector (vector) v. Syntax is:
v.pop_back();
It does not contain any parameters.
It does not return any value.
The following figure shows how the pop_back() function works:
The following figure shows how to use the pop_back() function to delete the last element of a vector (vector).
Let's see a simple example.
#include<iostream> #include<vector> using namespace std; int main() { vector<string> v{"welcome","to","www.oldtoolbag.com","tutorial"}; cout<<"Initial string is :"; for(int i=0; i<v.size(); i++{ cout << v[i] << " \t"; } cout<<'\n'; cout << "After deleting the last string, the string becomes:\"; v.pop_back(); for(int i = 0; i < v.size(); i++{ cout << v[i] << " \t"; } return 0; }
Output:
The initial string is: welcome to www.oldtoolbag.com tutorial After deleting the last string, the string becomes: welcome to www.oldtoolbag.com
In this example, the last string is deleted using the pop_back() function.