fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <iostream>
  4. #include <sstream>
  5. #include <vector>
  6. #include <iterator>
  7.  
  8. std::vector<std::string> tokenize(const std::string& s)
  9. {
  10. using iter = std::istream_iterator<std::string>;
  11.  
  12. std::istringstream is(s);
  13. return std::vector<std::string>(iter(is), iter());
  14. }
  15.  
  16. int main()
  17. {
  18. auto tokens = tokenize("test apple");
  19.  
  20. for (auto& token : tokens)
  21. std::cout << '"' << token << "\"\n";
  22. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
"test"
"apple"