移除指定位置处的元素。
iterator erase(iterator where);
iterator erase(iterator first, iterator last);
bool erase(key_type key)
参数
首先
清除的范围开头。键
清除的键值。last
清除范围的末尾。where
清除的元素。
备注
第一个成员函数中移除该控件序列的元素指向由 where,并返回指定保持在元素外的第一个元素中移除的迭代器,或者 map::end (STL/CLR)() ,如果不存在这样的元素。使用该移除一个元素。
第二个成员函数移除控件序列的元素在范围 [first,last)的,并返回指定保持在所有元素外的第一个元素中移除的迭代器,或者 end() ,如果不存在这样的元素。使用该移除零个或多个连续的元素。
第三个成员函数移除项具有相同顺序对 key控件序列的所有元素,并返回元素数的计数移除的。使用该移除和计数与指定的键的所有元素。
每个元素抹除所用时间比例与元素数的对数在控件的序列。
示例
// cliext_map_erase.cpp
// compile with: /clr
#include <cliext/map>
typedef cliext::map<wchar_t, int> Mymap;
int main()
{
cliext::map<wchar_t, int> c1;
c1.insert(cliext::map<wchar_t, int>::make_value(L'a', 1));
c1.insert(cliext::map<wchar_t, int>::make_value(L'b', 2));
c1.insert(cliext::map<wchar_t, int>::make_value(L'c', 3));
// display contents " [a 1] [b 2] [c 3]"
for each (cliext::map<wchar_t, int>::value_type elem in c1)
System::Console::Write(" [{0} {1}]", elem->first, elem->second);
System::Console::WriteLine();
// erase an element and reinspect
cliext::map<wchar_t, int>::iterator it =
c1.erase(c1.begin());
System::Console::WriteLine("erase(begin()) = [{0} {1}]",
it->first, it->second);
// add elements and display " b c d e"
c1.insert(cliext::map<wchar_t, int>::make_value(L'd', 4));
c1.insert(cliext::map<wchar_t, int>::make_value(L'e', 5));
for each (cliext::map<wchar_t, int>::value_type elem in c1)
System::Console::Write(" [{0} {1}]", elem->first, elem->second);
System::Console::WriteLine();
// erase all but end
it = c1.end();
it = c1.erase(c1.begin(), --it);
System::Console::WriteLine("erase(begin(), end()-1) = [{0} {1}]",
it->first, it->second);
System::Console::WriteLine("size() = {0}", c1.size());
// erase end
System::Console::WriteLine("erase(L'x') = {0}", c1.erase(L'x'));
System::Console::WriteLine("erase(L'e') = {0}", c1.erase(L'e'));
return (0);
}
要求
标题: <cliext/映射>
命名空间: cliext