You can split a string (using a string stream) into a vector, and then use std::find_first_ofwith four iterators.
Here is a complete code example
#include <iostream>
#include <string>
#include <algorithm>
#include <sstream>
#include <vector>
#include <iterator>
using namespace std;
int main(void)
{
string str("aaa bbb ccc ddd eee fff ggg");
vector<string> vs;
vs.push_back("ccc");
vs.push_back("fff");
vector<string> scheck;
istringstream instr(str);
copy(istream_iterator<string>(instr),
istream_iterator<string>(),
back_inserter(scheck));
vector<string>::iterator it = find_first_of (scheck.begin(), scheck.end(), vs.begin(), vs.end());
if (it != scheck.end())
cout << "first match is: " << *it << endl;
return 0;
}
source
share