fork(1) download
  1. #include <sstream>
  2. #include <string>
  3. #include <fstream>
  4. #include <iostream>
  5. #include <vector>
  6. #include <iterator>
  7. #include <algorithm>
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13. string line;
  14. istringstream strm;
  15. vector<vector<int>> table;
  16. int num;
  17. while (getline(cin, line))
  18. {
  19. istringstream strm(line);
  20. vector<int> vInt;
  21. while ( strm >> num )
  22. vInt.push_back(num);
  23. table.push_back(vInt);
  24. }
  25.  
  26. // output results
  27. cout << "The table has this many rows: " << table.size() << endl;
  28. cout << "The data for each row: " << endl;
  29. for (size_t i = 0; i < table.size(); ++i)
  30. {
  31. copy(table[i].begin(), table[i].end(), ostream_iterator<int>(cout, " "));
  32. cout << endl;
  33. }
  34. }
  35.  
Success #stdin #stdout 0s 3240KB
stdin
1 2 3 4 5 6 7
10 20 30 40 50 60 70
100 200 300 400 500 600 700
stdout
The table has this many rows: 3
The data for each row: 
1 2 3 4 5 6 7 
10 20 30 40 50 60 70 
100 200 300 400 500 600 700