STL_set——set::find
来源:互联网 发布:ubuntu用终端设置中文 编辑:程序博客网 时间:2024/06/05 23:03
Reference:
Returns an iterator addressing the location of an element in a set that has a key equivalent to a specified key.
Function:
iterator find(
const Key& _Key
) const;
const_iterator find(
const Key& _Key
) const;
Parameter:
_Key:The argument key to be matched by the sort key of an element from the set being searched.
Return Value:
An iterator or const_iterator that addresses the location of an element equivalent to a specified key or that addresses the location succeeding the last element in the set if no match is found for the key.
Remarks:
The member function returns an iterator that addresses an element in the set whose sort key is equivalent to the argument key under a binary predicate that induces an ordering based on a less-than comparability relation.
If the return value of find is assigned to a const_iterator, the set object cannot be modified. If the return value of find is assigned to an iterator, the set object can be modified.
Example:
Output:
The element of set s1 with a key of 20 is: 20.
The set s1 doesn't have an element with a key of 40.
The element of s1 with a key matching that of the last element is: 30.
Returns an iterator addressing the location of an element in a set that has a key equivalent to a specified key.
Function:
iterator find(
const Key& _Key
) const;
const_iterator find(
const Key& _Key
) const;
Parameter:
_Key:The argument key to be matched by the sort key of an element from the set being searched.
Return Value:
An iterator or const_iterator that addresses the location of an element equivalent to a specified key or that addresses the location succeeding the last element in the set if no match is found for the key.
Remarks:
The member function returns an iterator that addresses an element in the set whose sort key is equivalent to the argument key under a binary predicate that induces an ordering based on a less-than comparability relation.
If the return value of find is assigned to a const_iterator, the set object cannot be modified. If the return value of find is assigned to an iterator, the set object can be modified.
Example:
#include <set>#include <iostream>int main( ){ using namespace std; set <int> s1; set <int> :: const_iterator s1_AcIter, s1_RcIter; s1.insert( 10 ); s1.insert( 20 ); s1.insert( 30 ); s1_RcIter = s1.find( 20 ); cout << "The element of set s1 with a key of 20 is: " << *s1_RcIter << "." << endl; s1_RcIter = s1.find( 40 ); // If no match is found for the key, end( ) is returned if ( s1_RcIter == s1.end( ) ) cout << "The set s1 doesn't have an element " << "with a key of 40." << endl; else cout << "The element of set s1 with a key of 40 is: " << *s1_RcIter << "." << endl; // The element at a specific location in the set can be found // by using a dereferenced iterator addressing the location s1_AcIter = s1.end( ); s1_AcIter--; s1_RcIter = s1.find( *s1_AcIter ); cout << "The element of s1 with a key matching " << "that of the last element is: " << *s1_RcIter << "." << endl;}
Output:
The element of set s1 with a key of 20 is: 20.
The set s1 doesn't have an element with a key of 40.
The element of s1 with a key matching that of the last element is: 30.
0 0
- STL_set——set::find
- STL_set——set::begin
- STL_set——set::clear
- STL_set——set::count
- STL_set——set::empty
- STL_set——set::end
- STL_set——set::equal_range
- STL_set——set::erase
- STL_set——set::insert
- STL_set——set::size
- STL_set
- stl_set
- STL_set
- stl_set
- STL_set
- stl_set.h
- STL_set用法
- set集中查找find
- Java IO 使用时具体对象的确定
- mac平台wxWidgets编译及测试
- cocos2d-x2.2.4 进度条实现
- linux 内存管理系列1
- poj1503(高精度运算之大数相加)
- STL_set——set::find
- 二叉查找树的元素删除算法
- 查看主板支持最大内存的方法
- ubuntu 14.04 安装后折腾 2 天工作环境配置
- 微博授权后不会跳回应用
- 简单四则运算
- poj3984(迷宫问题)
- Android学习之笔记---WebView的使用
- Win7 x64 VC6无法调试程序的bug解决方法