unordered_multimap::find()
描述 (Description)
C ++函数std::unordered_multimap::find()查找与键k关联的元素。
如果操作成功,则方法返回指向该元素的迭代器,否则返回指向unordered_map :: end()的迭代器。
声明 (Declaration)
以下是std :: unordered_multimap :: find()函数形式std :: unordered_map()头的声明。
C++11
iterator find (const key_type& k);
const_iterator find (const key_type& k) const;
参数 (Parameters)
k - 要搜索的密钥。
返回值
如果object是常量限定的,则method返回一个常量迭代器,否则返回非常量迭代器。
时间复杂
常数,即平均情况下为O(1)。
在最坏的情况下线性即O(n)。
例子 (Example)
以下示例显示了std :: unordered_multimap :: find()函数的用法。
#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}
};
auto it = umm.find('b');
cout << "Iterator point to " << it->first << " = " << it->second << endl;
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 -
Iterator point to b = 2