STL算法---find()

一.find运算

假设有一个int型的vector对象,名为vec,我们想知道其中是否包含某个特定值

解决这个问题最简单的方法时使用标准库提供的find运算:

// value we'll look for
int search_value = 42;

//call find to see if that value is present
vector<int>::const_iterator result = find(vec.begin() , vec.end() , search_value);

//report the result
cout<<"The value "<<search_value
<<(result == vec.end() ? " is not present" : "is present")
<<endl;
posted @ 2017-07-03 15:58  ren_zhg1992  阅读(100)  评论(0)    收藏  举报