Advertisement
axyd

Read File to 2D Double vector

Oct 12th, 2016
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1.     vector<vector<double> > vc;
  2. //File to vector http://stackoverflow.com/a/23072197/6793751
  3.  
  4.     string line;
  5.     ifstream fileStream(file);
  6.     while(getline(fileStream, line, '\n')) {
  7.         stringstream ss(line);
  8.         vector<double> numbers;
  9.         string in_line;
  10.         while(getline (ss, in_line, ',')) {
  11.             numbers.push_back(stod(in_line, 0));
  12.         }
  13.         vc.push_back(numbers);
  14.     }
  15.  
  16.     /*TEST: GRADES FILE READ*/
  17. //  int rows=vc.size();
  18. //  for(int x=0; x<rows; ++x) {
  19. //      int cols=vc[x].size();
  20. //      for(int y=0; y<cols; ++y) {
  21. //          if(y<(cols-1)) printf(" %.1F, ",vc[x][y]);
  22. //          else(printf(" %.1F ",vc[x][y]));
  23. //      }
  24. //      cout<<endl;
  25. //  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement