C++ Unordered_map 库 - end() 函数
描述
C++ 函数 std::unordered_map::end() 返回一个迭代器,它指向 unordered_map 中的 past-the-end 元素。
声明
以下是 std::unordered_map::end() 函数形式 std::unordered_map 头的声明。
C++11
iterator end() noexcept; const_iterator end() const noexcept;
参数
None
返回值
如果 object 是常量限定的,则方法返回常量迭代器,否则返回非常量迭代器。
异常
这个成员函数从不抛出异常。
时间复杂度
常数,即 O(1)
示例
以下示例显示了 std::unordered_map::end() 函数的用法。
#include <iostream>
#include <unordered_map>
using namespace std;
int main(void) {
unordered_map<char, int> um = {
{'a', 1},
{'b', 2},
{'c', 3},
{'d', 4},
{'e', 5}
};
cout << "Unordered map contains following elements" << endl;
for (auto it = um.begin(); it != um.end(); ++it)
cout << it->first << " = " << it->second << endl;
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 −
Unordered map contains following elements e = 5 a = 1 b = 2 c = 3 d = 4

