#include <iostream> #include <vector> #include <algorithm> #include <functional> using namespace std; void print(const int& temp){ cout<<temp<<endl; } int main() { const int ARRAY_SIZE=8; int IntArray[ARRAY_SIZE]={1,2,3,4,5,6,7}; vector<int> myvt; vector<int>::iterator location_index; for(int i=0;i<8;++i){ myvt.push_back(IntArray[i]); } for_each(myvt.begin(),myvt.end(),print); location_index=find(myvt.begin(),myvt.end(),2); //find函数 cout<<"数字2的下标是:"<<(location_index-myvt.begin())<<endl; location_index=find_if(myvt.begin(),myvt.end(),bind2nd(greater<int>(),5)); cout<<"第一个大于5的数字的下标是:"<<(location_index-myvt.begin())<<endl; return 0; }
C++ STL vector容器元素的查找和搜索 find() find_if()函数的使用
猜你喜欢
转载自blog.csdn.net/ibelievesunshine/article/details/80214158
今日推荐
周排行