目录

unordered_multimap::erase()

描述 (Description)

C ++函数std::unordered_multimap::erase()位置移除unordered_multimap的单个元素。

此成员函数将unordered_multimap的大小减小一个。

声明 (Declaration)

以下是std :: unordered_multimap :: erase()函数形式std :: unordered_map()头的声明。

C++11

iterator erase(const_iterator position);

参数 (Parameters)

position - 要移除的元素的迭代器。

返回值

返回一个迭代器,指向紧跟最后一个元素擦除后的位置。

时间复杂

线性即O(n)

例子 (Example)

以下示例显示了std :: unordered_multimap :: erase()函数的用法。

#include <iostream>
#include <unordered_map>
using namespace std;
int main(void) {
   unordered_multimap<char, int> umm = {
            {'a', 1},
            {'b', 2},
            {'c', 3},
            {'d', 4},
            {'e', 5}
            };
   cout << "Unordered_multimap contains following elements "
        << "before remove operation" << endl;
   for (auto it = umm.begin(); it != umm.end(); ++it)
      cout << it->first << " = " << it->second << endl;
   cout << endl;
   umm.erase(umm.begin());
   cout << "Unordered_multimap contains following elements "
        << "after remove operation" << endl;
   for (auto it = umm.begin(); it != umm.end(); ++it)
      cout << it->first << " = " << it->second << endl;
   return 0;
}

让我们编译并运行上面的程序,这将产生以下结果 -

Unordered_multimap contains following elements before remove operation
e = 5
a = 1
b = 2
c = 3
d = 4
Unordered_multimap contains following elements after remove operation
a = 1
b = 2
c = 3
d = 4
↑回到顶部↑
WIKI教程 @2018