标签:
刚开始,我直接采用赋值的方式,但是都显示错误,后来上网看了一圈,才知道,vector要用push_back来进行赋值。
#include<iostream> #include<vector> using namespace std; bool search_vec(vector<int>::iterator beg,vector<int>::iterator end,int val) { for(;beg!=end;beg++) if(*beg==val) return true; return false; } int main() { vector<int> ilist; ilist.push_back(1); ilist.push_back(2); ilist.push_back(3); ilist.push_back(4); ilist.push_back(5); ilist.push_back(6); ilist.push_back(7); cout<<search_vec(ilist.begin(),ilist.end(),3)<<endl; cout<<search_vec(ilist.begin(),ilist.end(),8)<<endl; return 0; }
标签:
原文地址:http://www.cnblogs.com/gtt1025/p/5859585.html