Using pop_back to Erase the Last Element : vector push pop heap « vector « C++ Tutorial






#include <iostream>
#include <vector>

int main ()
{
    using namespace std;

    vector <int> v;

    v.push_back (50);
    v.push_back (1);
    v.push_back (987);
    v.push_back (1001);

    cout << "The vector contains ";
    cout << v.size ();
    cout << " elements before calling pop_back" << endl;

    // Erase one element at the end
    v.pop_back ();

    cout << "The vector contains ";
    cout << v.size ();
    cout << " elements after calling pop_back" << endl;

    cout << "Enumerating items in the vector... " << endl;

    unsigned int nElementIndex = 0;
    while (nElementIndex < v.size ())
    {
        cout << "Element at position " << nElementIndex << " is: ";
        cout << v [nElementIndex] << endl;

        // move to the next element
        ++ nElementIndex;
    }

    return 0;
}








16.20.vector push pop heap
16.20.1.Perform the heapsort with push_heap and pop_heap
16.20.2.Using pop_back to Erase the Last Element
16.20.3.pop_back from a vector
16.20.4.Demonstrating the STL vector push_back functions