list::remove
清除與指定的值 list 中的項目。
void remove(
const Type& _Val
);
參數
- _Val
如果值是由元素持有,則當元素被從 list 移除時,該值也會被移除。
備註
項目保持的順序不受影響。
範例
// list_remove.cpp
// compile with: /EHsc
#include <list>
#include <iostream>
int main( )
{
using namespace std;
list <int> c1;
list <int>::iterator c1_Iter, c2_Iter;
c1.push_back( 5 );
c1.push_back( 100 );
c1.push_back( 5 );
c1.push_back( 200 );
c1.push_back( 5 );
c1.push_back( 300 );
cout << "The initial list is c1 =";
for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
cout << " " << *c1_Iter;
cout << endl;
list <int> c2 = c1;
c2.remove( 5 );
cout << "After removing elements with value 5, the list becomes c2 =";
for ( c2_Iter = c2.begin( ); c2_Iter != c2.end( ); c2_Iter++ )
cout << " " << *c2_Iter;
cout << endl;
}
需求
標題: <list>
命名空間: std