#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;
}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐