Delete the last element of the vector : vector begin end « vector « C++ Tutorial






#include <iostream>
#include <vector>

using namespace std;
typedef vector<int> INTVECTOR;
const int ARRAY_SIZE = 4;

int main(void)
{
   INTVECTOR theVector;

   // Intialize the array to contain the members [100, 200, 300, 400]
   for (int cEachItem = 0; cEachItem < ARRAY_SIZE; cEachItem++)
      theVector.push_back((cEachItem + 1) * 100);

   cout << "First element: " << theVector.front() << endl;
   cout << "Last element: " << theVector.back() << endl;
   cout << "Elements in vector: " << theVector.size() << endl;

   cout << "Deleting last element." << endl;
   theVector.erase(theVector.end() - 1);
   cout << "New last element is: " << theVector.back() << endl;

}








16.5.vector begin end
16.5.1.Delete the last element of the vector
16.5.2.Delete the first element of the vector
16.5.3.Get the first element in a vector
16.5.4.Get the last element in a vector
16.5.5.Assign elements in vector a value through an iterator