#include "stdafx.h" /* // TEMPLATE FUNCTION find template<class _InIt, class _Ty> inline _InIt _Find(_InIt _First, _InIt _Last, const _Ty& _Val) { // find first matching _Val _DEBUG_RANGE(_First, _Last); for (; _First != _Last; ++_First) if (*_First == _Val) break; return (_First); } inline const char *_Find(const char *_First, const char *_Last, int _Val) { // find first char that matches _Val _DEBUG_RANGE(_First, _Last); _First = (const char *)::memchr(_First, _Val, _Last - _First); return (_First == 0 ? _Last : _First); } inline const signed char *_Find(const signed char *_First, const signed char *_Last, int _Val) { // find first signed char that matches _Val _DEBUG_RANGE(_First, _Last); _First = (const signed char *)::memchr(_First, _Val, _Last - _First); return (_First == 0 ? _Last : _First); } inline const unsigned char *_Find(const unsigned char *_First, const unsigned char *_Last, int _Val) { // find first unsigned char that matches _Val _DEBUG_RANGE(_First, _Last); _First = (const unsigned char *)::memchr(_First, _Val, _Last - _First); return (_First == 0 ? _Last : _First); } template<class _InIt, class _Ty> inline _InIt find(_InIt _First, _InIt _Last, const _Ty& _Val) { // find first matching _Val _ASSIGN_FROM_BASE(_First, _Find(_CHECKED_BASE(_First), _CHECKED_BASE(_Last), _Val)); return (_First); } */ //*********************by vincent http://my.csdn.net/sunboyiris ************************// #include "stdafx.h" #include "algorithm" #include "list" #include "iostream" using namespace std; int _tmain(int argc, _TCHAR* argv[]) { list<int> l; for(int i=0;i<10;i++) { l.push_back(i); } //引用指针 int count1=0; list<int>::iterator iter; for(iter=l.begin();iter!=l.end();iter++) { count1++; } cout<<count1<<endl; list<int>::iterator iter1=find(l.begin(),l.end(),9); if(iter1!=l.end()) { cout<<"找到元素9"<<endl; cout<<"前一个元素为:"<<*(--iter1)<<endl; } return 0; }
STL(2)find函数
原创王孟贤 ©著作权
文章分类
©著作权归作者所有:来自51CTO博客作者王孟贤的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:STL(3) find_if函数
下一篇:(6)3n+1猜想 实现
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
STL之adjacent_find
adjacent_find是一个不破坏操作数据的模
操作数 迭代器 头文件