push_back

Syntax:

    #include <vector>
    void push_back( const TYPE& val );

The push_back() function appends val to the end of the vector. For example, the following code puts 10 integers into a vector:

     vector<int> the_vector;
     for( int i = 0; i < 10; i++ ) {
       the_vector.push_back( i );
     }

When displayed, the resulting vector would look like this:

   0 1 2 3 4 5 6 7 8 9

push_back() runs in constant time in the best case scenario.

Related Topics: assign, insert, pop_back