Mega Code Archive

 
Categories / C++ Tutorial / Vector
 

Delete the first element of the vector

#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;    // Delete the first element of the vector.    theVector.erase(theVector.begin());    cout << "New first element is: " << theVector.front() << endl;    cout << "Elements in vector: " << theVector.size() << endl; }