Generally to get the last element and remove it
I have to use stl::back
and then the stl::pop_back
#include <iostream>
#include <vector>
int main()
{
// Create a vector containing integers
std::vector<int> v = {7, 5, 16, 8};
// Add two more integers to vector
auto x= v.back();
v.pop_back();
std::cout<<"last value removed was"<<x<<"\n";
// Iterate and print values of vector
for(int n : v) {
std::cout << n << '\n';
}
}
Is there a way or any other stl by which I can use the pop_back() returns the last element and then remove .Just use a single stl
why is pop_back() just implemented to remove it would have been better if it could return as well .Any reason it is implemented just to remove