Get the last element in a 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 << "Last element: " << 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