菜鸟问个search_n的问题
int main()
{
int ia[]={5,2,3,11,7,11};
vector<int> sva(ia,ia+6);
vector<int>::iterator iter=sva.begin();
//有问题
iter=search_n(sva.begin(),sva.end(),2,3,greater<int>());
cout<<"it is:"<<*(iter)<<endl;
为什么出来的值是7而不是11啊,不是说返回符合序列的第一个元素的值么。
[解决办法]
template <class ForwardIterator, class Size, class T, class BinaryPredicate>
ForwardIterator search_n ( ForwardIterator first, ForwardIterator last,
Size count, const T& value, BinaryPredicate pred );
count
Minimum number of successive elements meeting the predicate to be considered a match.
Its type is an integral type or some other type convertible to it.
value
Individual value to be compared, or to be used as argument for pred (in the second version).
Its type has to support the appropriate equality comparison, for the first version.
return value
An iterator to the first element of the first occurrence of the succession of count equal values in [first,last).
If the sequence is not found, the function returns last.
见说明 你的count是 2 也就是第二个符合条件的会被返回
[解决办法]
count
Minimum number of successive elements meeting the predicate to be considered a match.
Its type is an integral type or some other type convertible to it.
这句话的意思 大概就是: 返回第count个符合谓语predicate的迭代器
[解决办法]
http://www.cplusplus.com/reference/
[解决办法]
这个函数的功能岂不是鸡肋,必须连续。。。。。
如果想搜索一个字符串中的字串,这个子串出现的次数很多次,
还不如直接用search进行。。。。。。。
初学者问个search_n的有关问题
菜鸟问个search_n的问题int main(){int ia[]{5,2,3,11,7,11}vectorint sva(ia,ia+6)vectorint::ite
