Aracılığıyla paylaş


list::resize

Bir liste için yeni bir boyutunu belirtir.

void resize(
   size_type _Newsize
);
void resize(
   size_type _Newsize,
   Type _Val
);

Parametreler

  • _Newsize
    Listeye yeni boyutu.

  • _Val
    Yeni boyutu büyükse, listeye eklenecek yeni öğeler değerinin, özgün boyutu.Değer atlanırsa, yeni öğeler sınıfı için varsayılan değeri atanır.

Notlar

Listenin boyutu, istenen boyutundan az ise _Newsize, istenen boyuta ulaşıncaya kadar öğeler listesine eklenir.

Listenin boyutu istenen boyutundan daha büyük ise, liste boyuta ulaşıncaya kadar listenin sonuna yakın öğeler silinir _Newsize.

Listenin bugünkü boyutu istenen boyuta aynı ise, hiçbir işlem yapılmaz.

Boyut listesinin geçerli boyutunu yansıtır.

Örnek

// list_resize.cpp
// compile with: /EHsc
#include <list>
#include <iostream>

int main( )
{ 
   using namespace std;
   list <int> c1;
   
   c1.push_back( 10 );
   c1.push_back( 20 );
   c1.push_back( 30 );

   c1.resize( 4,40 );
   cout << "The size of c1 is " << c1.size( ) << endl;
   cout << "The value of the last element is " << c1.back( ) << endl;

   c1.resize( 5 );
   cout << "The size of c1 is now " << c1.size( ) << endl;
   cout << "The value of the last element is now " << c1.back( ) << endl;

   c1.resize( 2 );
   cout << "The reduced size of c1 is: " << c1.size( ) << endl;
   cout << "The value of the last element is now " << c1.back( ) << endl;
}
  

Gereksinimler

Başlık: <list>

Namespace: std

Ayrıca bkz.

Başvuru

list Class

Standart Şablon Kütüphanesi