c++ - Inside a std::string, is it possible to find the first of a set of strings without using a loop? -


inside std::string, possible find first of set of strings without using loop?

e.g.:

std::string str("aaa bbb ccc ddd eee fff ggg"); std::vector<std::string> vs; vs.push_back("ccc"); vs.push_back("fff"); size_t pos = 0 pos = str.find(vs, pos);      //< pseudo code 

thank you!

you split string (using stringstream) vector , use std::find_first_of 4 iterators.

here 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 = find_first_of (scheck.begin(), scheck.end(), vs.begin(), vs.end());   if (it != scheck.end())     cout << "first match is: " << *it << endl;    return 0; } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -