fork download
  1. #include <list>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <iterator>
  5. #include <string>
  6.  
  7. std::list<std::list<std::string>> split(const std::list<std::string>& bulk)
  8. {
  9. std::list<std::list<std::string>> splitdata;
  10. for(auto& str: bulk)
  11. {
  12. std::istringstream buf(str);
  13. splitdata.emplace_back(
  14. std::istream_iterator<std::string>(buf),
  15. std::istream_iterator<std::string>());
  16. }
  17. return splitdata;
  18. }
  19.  
  20. int main()
  21. {
  22. std::list<std::string> in = {"this is an example", "this is another"};
  23. std::list<std::list<std::string>> out = split(in);
  24. for(auto& row: out) {
  25. for(auto& str: row)
  26. std::cout << "'" << str << "' ";
  27. std::cout << '\n';
  28. }
  29. }
  30.  
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
'this' 'is' 'an' 'example' 
'this' 'is' 'another'