fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. #include <algorithm>
  5. #include <iterator>
  6. #include <list>
  7.  
  8. int main()
  9. {
  10. std::string str;
  11. std::string tokens;
  12. std::cout << "string:\n";
  13. std::getline(std::cin, str);
  14. std::cout << "tokens:\n";
  15. std::cin >> tokens;
  16. using isit = std::istream_iterator<std::string>;
  17. std::stringstream ss(str);
  18. std::list<std::string> words( isit( ss ), ( isit() ) );
  19. str.clear();
  20. ss.clear();
  21. ss.str(str);
  22. std::copy_if( begin(words), end(words), std::ostream_iterator<std::string>(ss, " "),
  23. [&tokens](const std::string &word)
  24. { return word.find_first_of(tokens) == std::string::npos; } );
  25. std::cout << "result:\n";
  26. std::cout << ss.str();
  27. return 0;
  28. }
Success #stdin #stdout 0s 3480KB
stdin
To be, or not to be: that is the question
en
stdout
string:
tokens:
result:
To or to that is