#include<algorithm>
#include<vector>
#include<iostream>
using namespace std;
int main()
{
vector<int>v;
v.push_back(28);
v.push_back(12);
v.push_back(2);
v.push_back(2);
v.push_back(2);
v.push_back(19);
vector<int>::iterator pos;
// Search the vector from beginning to end three occurrences of element 2
pos=search_n(v.begin(), v.end(),3,2);
// cout<<"Value of Pos is "<<pos<<endl;
while(pos!=v.end())
{
cout<<"Distance of pos from beginning of the vector" ;
cout<<"distance(v.begin(),pos)+1<<endl;
++pos;
pos=search(pos, v.end(), 3,2);
}
return(0);
}
The following program displays the occurrence of the repeated set of elements in a vector container. The program illustrates search_n () and distance() function.