We recommend using Visual Studio 2017

list::resize (STL/CLR)

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at list::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.

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());   
    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  

Header: <cliext/list>

Namespace: cliext

list (STL/CLR)
list::clear (STL/CLR)
list::erase (STL/CLR)
list::insert (STL/CLR)

Show: