fork(1) download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. #include <vector>
  5.  
  6. std::istringstream in(
  7. "Steven Seagal\n"
  8. "1234 Post Drive\n"
  9. "Ventura, CA 90734\n"
  10. "\n"
  11. "Adam Sandler\n"
  12. "356 Golf Street\n"
  13. "Calabasas, CA 92136\n"
  14. );
  15.  
  16. int main()
  17. {
  18. std::vector<std::vector<std::string>> lines ;
  19.  
  20. std::string line ;
  21. while (std::getline(in, line))
  22. {
  23. std::vector<std::string> tokens ;
  24. std::istringstream ls(line) ;
  25. std::string token ;
  26.  
  27. while ( ls >> token )
  28. tokens.push_back(token) ;
  29.  
  30. if ( tokens.size() ) // skip empty lines.
  31. lines.emplace_back(std::move(tokens)) ;
  32. }
  33.  
  34. for ( auto& line : lines )
  35. {
  36. for ( auto& token : line )
  37. std::cout << token << ' ' ;
  38. std::cout << '\n';
  39. }
  40. }
Success #stdin #stdout 0s 3436KB
stdin
Standard input is empty
stdout
Steven Seagal 
1234 Post Drive 
Ventura, CA 90734 
Adam Sandler 
356 Golf Street 
Calabasas, CA 92136