std::map::find
iterator find (const key_type& k); const_iterator find (const key_type& k) const;
Searches the container for an element with a key equivalent to k and returns an iterator to it if found, otherwise it returns an iterator to map::end.
Two keys are considered equivalent if the container's comparison object returns false reflexively (i.e., no matter the order in which the elements are passed as arguments).
Another member function, map::count, can be used to just check whether a particular key exists.
Parameters
- k
- Key to be searched for.
Member type key_type is the type of the keys for the elements in the container, defined in map as an alias of its first template parameter (Key).
Return value
An iterator to the element, if an element with specified key is found, or map::end otherwise.
If the map object is const-qualified, the function returns a const_iterator. Otherwise, it returns an iterator.
Member types iterator and const_iterator are bidirectional iterator types pointing to elements (of type value_type).
Notice that value_type in map containers is an alias of pair<const key_type, mapped_type>.
Example
|
|
Output:
elements in mymap: a => 50 c => 150 d => 200
|
原文链接: https://www.cnblogs.com/the-tops/p/5586848.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/235231
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!