fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <sstream>
  6. #include <iterator>
  7. using namespace std;
  8.  
  9.  
  10. int main() {
  11. string input="Hello, world ! I whish you all \na happy new year 2016 !";
  12. vector<string> sentence;
  13. vector<string> search{"We", "You", "I"};
  14.  
  15. stringstream sst(input); // split the string into its pieces
  16. string tmp;
  17. while (sst>>tmp)
  18. sentence.push_back(tmp);
  19.  
  20. // how to manipulate easily the vecotr of words
  21. copy(sentence.begin(), sentence.end(), ostream_iterator<string>(cout,"/"));
  22. cout<<endl;
  23. // search words
  24. auto it = find_first_of(sentence.begin(), sentence.end(),
  25. search.begin(), search.end());
  26.  
  27. // display remaining of the sentence
  28. copy(it , sentence.end(), ostream_iterator<string>(cout,"/"));
  29. cout<<endl;
  30.  
  31. stringstream so;
  32. copy(it , sentence.end(), ostream_iterator<string>(so," "));
  33. string result = so.str();
  34. cout<<result<<endl;
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
Hello,/world/!/I/whish/you/all/a/happy/new/year/2016/!/
I/whish/you/all/a/happy/new/year/2016/!/
I whish you all a happy new year 2016 !