Export (0) Print
Expand All

list::resize (STL/CLR)

Changes the number of elements.

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


New size of the controlled sequence.


Value of the padding element.

The member functions both ensure that list::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 list::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.

// cliext_list_resize.cpp 
// compile with: /clr 
#include <cliext/list> 
int main() 
// construct an empty container and pad with default values 
    cliext::list<wchar_t> c1; 
    System::Console::WriteLine("size() = {0}", c1.size()); 
    for each (wchar_t elem in c1) 
        System::Console::Write(" {0}", (int)elem); 
// resize to empty 
    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); 
    return (0); 
size() = 0 0 0 0 0 size() = 0 x x x x x

Header: <cliext/list>

Namespace: cliext

Community Additions

© 2014 Microsoft