64,637
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<vector>
#include <algorithm>
using namespace std;
int main()
{
int search_value=42;
vector<int> vec; //定义int型的vector
vec.push_back(1);//在vec中的最后插入一个元素,值为1
vec.push_back(42);//在vec中的最后插入一个新的元素,值为42
vec.push_back(5);//在vec中的最后位置插入一个新的元素,职位5 注意,此时元素的顺序为 1,42,5
vector<int>::const_iterator result=find(vec.begin(),vec.end(),search_value);
cout<<"The value"<<search_value<<(result==vec.end()?"is not present":"is present")<<endl;
return 0;
}
#include<iostream>
#include<vector>
#include <algorithm>
using namespace std;
int main()
{
int search_value=42;
vector<int> vec;
vec.push_back(1);
vec.push_back(42);
vec.push_back(5);
vector<int>::const_iterator result=find(vec.begin(),vec.end(),search_value);
cout<<"The value"<<search_value<<(result==vec.end()?"is not present":"is present")<<endl;
return 0;
}