- C 标准库
- C 标准库
- C++ 标准库
- C++ 库 - 主页
- C++ 库 - <fstream>
- C++ 库 - <iomanip>
- C++ 库 - <ios>
- C++ 库 - <iosfwd>
- C++ 库 - <iostream>
- C++ 库 - <istream>
- C++ 库 - <ostream>
- C++ 库 - <sstream>
- C++ 库 - <streambuf>
- C++ 库 - <原子>
- C++ 库 - <复杂>
- C++ 库 - <异常>
- C++ 库 - <功能>
- C++ 库 - <限制>
- C++ 库 - <语言环境>
- C++ 库 - <内存>
- C++ 库 - <新>
- C++ 库 - <数字>
- C++ 库 - <正则表达式>
- C++ 库 - <stdexcept>
- C++ 库 - <字符串>
- C++ 库 - <线程>
- C++ 库 - <元组>
- C++ 库 - <类型信息>
- C++ 库 - <实用程序>
- C++ 库 - <valarray>
C++ 地图库-erase() 函数
描述
C++ 函数std::multimap::erase()从多重映射中删除元素范围。
该成员函数减小了多重映射的大小。
宣言
以下是 std::multimap::erase() 函数形式 std::map 标头的声明。
C++11
iterator erase (const_iterator first, const_iterator last);
参数
first - 将迭代器输入到范围中的初始位置。
最后- 将迭代器输入到范围中的最终位置。
返回值
返回最后删除的元素后面的迭代器。
例外情况
如果抛出异常,对容器没有影响。
时间复杂度
第一个到最后一个之间的距离呈线性。
例子
以下示例显示了 std::multimap::erase() 函数的用法。
#include <iostream>
#include <map>
using namespace std;
int main(void) {
/* Multimap with duplicates */
multimap<char, int> m {
{'a', 1},
{'a', 2},
{'b', 3},
{'c', 4},
{'c', 5},
};
cout << "Multimap contains following elements before erase operation" << endl;
for (auto it = m.begin(); it != m.end(); ++it)
cout << it->first << " = " << it->second << endl;
auto it = m.begin();
++it, ++it;
it = m.erase(m.begin(), it);
cout << "Multimap contains following elements after erase operation" << endl;
for (auto it = m.begin(); it != m.end(); ++it)
cout << it->first << " = " << it->second << endl;
cout << "After erase operation iterator points to " << it->first
<< " = " << it->second << endl;
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 -
Multimap contains following elements before erase operation a = 1 a = 2 b = 3 c = 4 c = 5 Multimap contains following elements after erase operation b = 3 c = 4 c = 5 After erase operation iterator points to b = 3
地图.htm