axyd icon

Read File to 2D Double vector

axyd | PRO | 10/13/16 04:11:21 AM UTC | 0 ⭐ | 640 👁️ | Never ⏰ | []
C++ |

620 B

|

None

|

0 👍

/

0 👎

    vector<vector<double> > vc;
//File to vector http://stackoverflow.com/a/23072197/6793751
 
    string line;
    ifstream fileStream(file);
    while(getline(fileStream, line, '\n')) {
        stringstream ss(line);
        vector<double> numbers;
        string in_line;
        while(getline (ss, in_line, ',')) {
            numbers.push_back(stod(in_line, 0));
        }
        vc.push_back(numbers);
    }
 
    /*TEST: GRADES FILE READ*/
//  int rows=vc.size();
//  for(int x=0; x<rows; ++x) {
//      int cols=vc[x].size();
//      for(int y=0; y<cols; ++y) {
//          if(y<(cols-1)) printf(" %.1F, ",vc[x][y]);
//          else(printf(" %.1F ",vc[x][y]));
//      }
//      cout<<endl;
//  }

Comments