fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <sstream>
  5. #include <iterator>
  6.  
  7. std::vector<std::string> tokenize( std::string keyw )
  8. {
  9. const std::string delims = ",.:;_\n\r\t*-=()" ;
  10.  
  11. // replace each delimiter with a space
  12. for( char& c : keyw ) if( delims.find(c) != std::string::npos ) c = ' ' ;
  13.  
  14. // construct an input stream which reads from the string
  15. std::istringstream stm(keyw) ;
  16.  
  17. // read whitespace seperated tokens from the stream into a vector and return it
  18. return { std::istream_iterator<std::string>(stm),
  19. std::istream_iterator<std::string>() } ;
  20. }
  21.  
  22. int main()
  23. {
  24. for( const auto& s : tokenize( "./client --search hello sick papa dont " ) )
  25. std::cout << s << '\n' ;
  26. }
  27.  
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
/client
search
hello
sick
papa
dont