Program :
Code:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool mypredicate (int p, int q)
{
return (p==q);
}
int main ()
{
int mints[]={10,20,30,30,20,10,10,20};
vector<int> mvctr (mints,mints+8);
vector<int>::iterator i;
i = search_n (mvctr.begin(), mvctr.end(), 2, 30);
if (i!=mvctr.end())
cout << "two 30s found at position " << int(i-mvctr.begin()) << endl;
else
cout << "match not found" << endl;
i = search_n (mvctr.begin(), mvctr.end(), 2, 10, mprdct);
if (i!=mvctr.end())
cout << "two 10s found at position " << int(i-mvctr.begin()) << endl;
else
cout << "match not found" << endl;
return 0;
}
Output :
Code:
Two 30s found at position 2
Two 10s found at position 5
Bookmarks