list::erase (STL/CLR)

移除指定位置处的元素。

    iterator erase(iterator where);
    iterator erase(iterator first, iterator last);

参数

  • 首先
    清除的范围开头。

  • last
    清除范围的末尾。

  • where
    清除的元素。

备注

第一个成员函数中移除该控件序列的元素指向由 where。使用该移除一个元素。

第二个成员函数移除控件序列的元素在范围 [first,last)的。使用该移除零个或多个连续的元素。

两个成员函数返回指定保持在所有元素外的第一个元素中移除的迭代器,或者 list::end (STL/CLR)() ,如果不存在这样的元素。

清除元素时,元素副本数是线性在元素数。抹除结束和序列之间的接近程度的末尾。(清除一个或多个组件序列中的任何一端,元素复制不会发生。)

示例

// cliext_list_erase.cpp 
// compile with: /clr 
#include <cliext/list> 
 
int main() 
    { 
    cliext::list<wchar_t> c1; 
    c1.push_back(L'a'); 
    c1.push_back(L'b'); 
    c1.push_back(L'c'); 
 
// display initial contents " a b c" 
    for each (wchar_t elem in c1) 
        System::Console::Write(" {0}", elem); 
    System::Console::WriteLine(); 
 
// erase an element and reinspect 
    System::Console::WriteLine("erase(begin()) = {0}", 
        *c1.erase(c1.begin())); 
 
// add elements and display " b c d e" 
    c1.push_back(L'd'); 
    c1.push_back(L'e'); 
    for each (wchar_t elem in c1) 
        System::Console::Write(" {0}", elem); 
    System::Console::WriteLine(); 
 
// erase all but end 
    cliext::list<wchar_t>::iterator it = c1.end(); 
    System::Console::WriteLine("erase(begin(), end()-1) = {0}", 
        *c1.erase(c1.begin(), --it)); 
    System::Console::WriteLine("size() = {0}", c1.size()); 
    return (0); 
    } 
 
  

要求

标题: <cliext/列表>

命名空间: cliext

请参见

参考

list (STL/CLR)

list::clear (STL/CLR)