Share via


vector::resize (STL/CLR)

Changes the number of elements.

    void resize(size_type new_size);
    void resize(size_type new_size, value_type val);

Parameters

  • new_size
    New size of the controlled sequence.

  • val
    Value of the padding element.

Remarks

The member functions both ensure that vector::size (STL/CLR)() henceforth returns new_size. If it must make the controlled sequence longer, the first member function appends elements with value value_type(), while the second member function appends elements with value val. To make the controlled sequence shorter, both member functions effectively erase the last element vector::size (STL/CLR)() - new_size times. You use it to ensure that the controlled sequence has size new_size, by either trimming or padding the current controlled sequence.

Example

// cliext_vector_resize.cpp 
// compile with: /clr 
#include <cliext/vector> 
 
int main() 
    { 
// construct an empty container and pad with default values 
    cliext::vector<wchar_t> c1; 
    System::Console::WriteLine("size() = {0}", c1.size()); 
    c1.resize(4); 
    for each (wchar_t elem in c1) 
        System::Console::Write(" {0}", (int)elem); 
    System::Console::WriteLine(); 
 
// resize to empty 
    c1.resize(0); 
    System::Console::WriteLine("size() = {0}", c1.size()); 
 
// resize and pad 
    c1.resize(5, L'x'); 
    for each (wchar_t elem in c1) 
        System::Console::Write(" {0}", elem); 
    System::Console::WriteLine(); 
    return (0); 
    } 
 
size() = 0
 0 0 0 0
size() = 0
 x x x x x

Requirements

Header: <cliext/vector>

Namespace: cliext

See Also

Reference

vector (STL/CLR)

vector::clear (STL/CLR)

vector::erase (STL/CLR)

vector::insert (STL/CLR)