我对将数据从文件写入一维数组感到困惑

I'm confused in writing data from a file into a one dimensional array

本文关键字:一维数组 数据 文件      更新时间:2023-10-16

例如,我读入了一个包含;

12354343 12 12 35 87 48 100 65 435
45395893 23 12 65 45 23 098 44 233
12902440 23 09 20 04 40 054 00 100

如何将第一行放在数组的第一个元素中,将第二行放在第二个元素中等等?

我选择退出代码只是为了进行打开文件检查,以确保我的文件正在打开但我不确定其他是怎么回事

using namespace std;
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <iomanip>
int main()
{
const int data = 50;
int ray1[data];
int Id,score1,score2,score3,score4,score5,score6,score7,score8,mid,lab,codelab,finalT;
cout << "Stdnt Id  ----- Assignments -----  Mi  Ex  CL  Fin" << endl;
cout << "________  _______________________  __  __  __  ___" << endl;
ifstream inFile;
inFile.open("assign1Input.txt");
 if (inFile)
{
    while (inFile >> Id)
    {
       for(Id = 0; Id < 50 ; Id++)
       {
         cout << Id << setw (2) << score1 << setw (1) << score2 << setw (1) << score3
         << setw (1) << score4 << setw (1) << score5 << setw (1) << score6 << setw (1) << score7
         << setw (1) << score8 << setw (2) << mid << setw (2) << lab << setw (2) << codelab
         << setw (2) << finalT << endl;
       }
    }
    inFile.close();
}
else
{
    cout << "ERROR" << endl;
}
return 0;
}
vector< vector< int > > data;
ifstream file;
string line;
while (getline(file, line))
{
    data.resize(data.size() + 1);
    ostringstream ss(line);
    int x;
    while (ss >> x)
    {
        data.back().push_back(x);
    }
}