C++ Multimap 库 - cend() 函数
描述
C++ 函数 std::multimap::cend() 返回一个常量迭代器,它指向多重映射的 past-the-end 元素。
声明
以下是 std::multimap::cend() 函数形式 std::map 头的声明。
C++11
const_iterator cend() const noexcept;
参数
None
返回值
返回一个常量迭代器。
异常
此成员函数从不抛出异常。
时间复杂度
常数,即 O(1)
示例
以下示例显示了 std::multimap::cend() 函数的用法。
#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:" << endl;
for (auto it = m.cbegin(); it != m.cend(); ++it)
cout << it->first << " = " << it->second << endl;
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 −
Multimap contains following elements: a = 1 a = 2 b = 3 c = 4 c = 5