C++ ifstream problem.I 想从 .csv 文件中读取 "coordinates" 但代码以某种方式读取文件两次并放入奇怪的数字

C++ ifstream problem.I want to read "coordinates" from a .csv file but somehow the code reads the file twice and it puts wierd numbers

我在尝试将坐标从 .csv 文件读取到二维数组并将其用作线性回归模型的输入时遇到问题。我知道如何从文件读取到数组,但我需要这些信息文件是双精度而不是字符串,所以我想我应该看看输出结果是什么。我无法理解 right.The 问题是文件的每一行都被读取了 30 次,我无法弄明白。 代码在这里:

    #include <iostream>
    #include <fstream>
    #include <sstream>
    #include <string>
    #include <cmath>
    #include <limits>
    #include <iomanip>
    #include <vector>
    using namespace std;


    int main()
    {
           cout<<setprecision(10);
           //vector<vector<double> > observ_matr;
           ifstream myfile("Salary_Data.csv");
           vector<vector<double> > vec;
           string line;
           while(getline(myfile,line))
           {
                  stringstream lineStream(line);
                  string cell;
                  vector<double> temp_vec;
                  while(getline(lineStream, cell, ','))
                  {
                          temp_vec.push_back(atof(cell.c_str()));
                  }
                  vec.push_back(temp_vec);
           }
           for(int i=0;i<vec.size();i++)
           {
                  for(int j=0;j<vec.size();j++)
                  {
                          cout<<vec[i][j]<<"\t\t";
                  }
                  cout<<endl;
           }
           //cout<<vec[1].size();

           return 0;
     }

"myfile" is this , this .csv file

The output i am getting after running the code is this:

问题出在这里...

    for (int j = 0; j < vec[i].size(); j++) // vec[i].size() instead of vec.size()