resize [C++ Reference]
Keywords: stl,vector,resize
Date: 2009-10-08T23:55:15-0700

[[resize]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- cz
- de
- es
- fr
- it
- jp
- nl
- pl
- ro
- ru
- sk
- tr
- tw

## resize

Syntax:

        #include <vector>
        void resize( size_type num, 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

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •