Demonstrate search() in vector
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
vector<char> vectorObject, vectorObject2;
vector<char>::iterator p;
char str1[] = "O, T, T, T";
char str2[] = "T";
int i;
for(i = 0; i <strlen(str1); i++)
vectorObject.push_back(str1[ i ]);
for(i = 0; i <strlen(str2); i++)
vectorObject2.push_back(str2[ i ]);
cout << "Contents of vectorObject: ";
for(i = 0; i <vectorObject.size(); i++)
cout << vectorObject[ i ];
cout << endl;
p = search(vectorObject.begin(), vectorObject.end(), vectorObject2.begin(), vectorObject2.end()); // find the first Two
cout << "Sequence beginning with T: ";
while(p != vectorObject.end())
cout << *p++;
cout << endl;
return 0;
}
Related examples in the same category