stl:vector:resize

C++ Reference

resize

Syntax:

    #include <vector>
    void resize( size_type num, const TYPE& val = TYPE() );

The function resize() changes the size of the vector to num. If val is specified then any newly-created elements will be initialized to have a value of val. The contents of the vector up to num will remain unchanged.

Example:

   vector<int> v;
   for( int i = 0; i < 10; ++i ) v.push_back(i);
   v.resize( 20, 0 );  // adds an additional 10 zeros to the end of v

This function runs in linear time.

Related Topics: Vector constructors, capacity, size