fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include <string>
  5. #include <vector>
  6.  
  7. int main()
  8. {
  9. std::vector<std::vector<int> > distances;
  10. //std::ifstream MyFile ("file.csv");
  11. std::istream &MyFile (std::cin);
  12. //if(MyFile.is_open())
  13. {
  14. std::string line;
  15. while(std::getline(MyFile, line))
  16. {
  17. std::istringstream row (line);
  18. distances.push_back(std::vector<int>());
  19. std::string cell;
  20. while(std::getline(row, cell, ','))
  21. {
  22. int dist;
  23. std::istringstream(cell) >> dist;
  24. distances.back().push_back(dist);
  25. }
  26. }
  27. }
  28.  
  29. for(std::size_t i = 0; i < distances.size(); ++i)
  30. {
  31. for(std::size_t j = 0; j < distances[i].size(); ++j)
  32. {
  33. std::cout << distances[i][j] << ' ' << std::flush;
  34. }
  35. std::cout << std::endl;
  36. }
  37. }
Success #stdin #stdout 0s 2996KB
stdin
0,1,2,3,4
4,3,2,1,0
9,8,7,6,5
5,6,7,8,9
stdout
0 1 2 3 4 
4 3 2 1 0 
9 8 7 6 5 
5 6 7 8 9