Use pop_back() to remove one element from vector. - C++ STL

C++ examples for STL:vector

Description

Use pop_back() to remove one element from vector.

Demo Code

#include <iostream>
#include <vector>
using namespace std;
void show(const char *msg, vector<int> vect);
int main() {/*ww  w .  j ava 2 s  . c  o  m*/
   vector<int> v(10);
   for(unsigned i=0; i < v.size(); ++i)
      v[i] = i*i;
   show("Contents of v: ", v);
   v.pop_back();
   show("v after back-popping one element: ", v);
   cout << endl;
   return 0;
}
void show(const char *msg, vector<int> vect) {
   cout << msg;
   for(unsigned i=0; i < vect.size(); ++i)
      cout << vect[i] << " ";
   cout << "\n";
}

Result


Related Tutorials