list::assign (STL Samples)
Nasıl kullanılacağı gösterilmiştir list::assign Visual C++ standart şablon kitaplığı (stl) işlevi.
void assign(
const_iterator First,
const_iterator Last
);
void assign(
size_type n,
const T& x = T( )
);
iterator erase(
iterator It
);
iterator erase(
iterator First,
iterator Last
); bool empty( ) const;
Notlar
[!NOT]
Prototip sınıfı/parametre adları üstbilgi dosyasında sürüm eşleşmiyor.Bazıları, okumayı kolaylaştırmak için değiştirildi.
İlk üye işlev tarafından denetlenen sırasını değiştirir *Bu sırası [First, Last).İkinci üye işlevi tarafından denetlenen sırasını değiştirir *Bu n değeri öğelerinin yinelenmesinin ile x.Üçüncü üye işlev için işaret ettiği tarafından denetlenen sırasının öğeyi kaldırır ,.Dördüncü üye işlevi aralıktaki denetlenen sırasının öğelerini kaldırır [First, Last).Her ikisi de kaldırıldı, herhangi bir öğenin dışında kalan ilk öğe atayan bir yineleyici döndürür veya Son tür bir öğe varsa.Son üye işlevini verir doğru boş bir denetlenen sırası.
Örnek
// assign.cpp
// compile with: /EHsc
//
// Shows various ways to assign and erase elements
// from a list<T>.
//
// Functions:
// list::assign
// list::empty
// list::erase
#include <list>
#include <iostream>
using namespace std ;
typedef list<int> LISTINT;
int main()
{
LISTINT listOne;
LISTINT listAnother;
LISTINT::iterator i;
// Add some data
listOne.push_front (2);
listOne.push_front (1);
listOne.push_back (3);
listAnother.push_front(4);
listAnother.assign(listOne.begin(), listOne.end());
// 1 2 3
for (i = listAnother.begin(); i != listAnother.end(); ++i)
cout << *i << " ";
cout << endl;
listAnother.assign(4, 1);
// 1 1 1 1
for (i = listAnother.begin(); i != listAnother.end(); ++i)
cout << *i << " ";
cout << endl;
listAnother.erase(listAnother.begin());
// 1 1 1
for (i = listAnother.begin(); i != listAnother.end(); ++i)
cout << *i << " ";
cout << endl;
listAnother.erase(listAnother.begin(), listAnother.end());
if (listAnother.empty())
cout << "All gone\n";
}
Çıktı
1 2 3
1 1 1 1
1 1 1
All gone
Gereksinimler
Başlık: <list>