English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The function returns the currentvectorReference to the last element.
The syntax of vector v is:
v.back();
This function does not contain any parameters.
This function returns the last element of the vector
Let's look at a simple example.
#include<iostream> #include<vector> using namespace std; int main() { vector<string> fruit{"mango","apple","banana"}; cout << fruit.back(); return 0; }
Output:
banana
In this example, the back() function displays the last element of the vector named 'fruit'.