The pop_back() function or method can deletes the last an element of the given specified vector. The pop_back() function can be executed in constant time. In the following an example, the elements can be popped out of the given specified vector after they can be added up in the summation function as follows :
Code:
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> mvctr;
int summation (0);
mvctr.push_back (100);
mvctr.push_back (200);
mvctr.push_back (300);
while (!mvctr.empty())
{
summation+=mvctr.back();
mvctr.pop_back();
}
cout << "The elements of mvctr summed " << summation << endl;
return 0;
}
Output:
Code:
The elements of mvctr summed 600
Bookmarks