首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::multimap::find

iterator find( const Key& key );

(1)

const_iterator find( const Key& key ) const;

(2)

template< class K > iterator find( const K& x );

(3)

(since C++14)

template< class K > const_iterator find( const K& x ) const;

(4)

(since C++14)

1,2%29找到一个密钥相当于key如果有几个元素key在容器中,任何一个都可以返回。

3,4%29找到一个键比较的元素等价物价值x。此重载仅在下列情况下才参与重载解析:Compare::is_transparent是有效的,并表示类型。它允许调用此函数,而无需构造Key

参数

key

-

key value of the element to search for

x

-

a value of any type that can be transparently compared with a key

返回值

元素的迭代器,该元素的密钥等价于key如果没有找到这样的元素,请参阅end()返回%29迭代器。

复杂性

容器大小的对数。

二次

代码语言:javascript
复制
#include <iostream>
#include <map>
 
int main()
{  
    std::multimap<int,char> example = {{1,'a'},{2,'b'}};
 
    auto search = example.find(2);
    if(search != example.end()) {
        std::cout << "Found " << search->first << " " << search->second << '\n';
    }
    else {
        std::cout << "Not found\n";
    }
}

二次

产出:

二次

代码语言:javascript
复制
Found 2 b

二次

另见

count

returns the number of elements matching specific key (public member function)

equal_range

returns range of elements matching a specific key (public member function)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券