我对将数据从文件写入一维数组感到困惑
I'm confused in writing data from a file into a one dimensional array
例如,我读入了一个包含;
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);
}
}
相关文章:
- 将二维数组的所有元素插入到一维数组中
- C++语法差异:二维和一维数组(指针算术)
- 将一维数组写入 CSV C++中的不同列?
- C++:将矩阵存储在一维数组中
- 如何在一维数组中的每个元素中都有多个int值
- 以C++填充一维数组
- 用于在一维数组上嵌套循环操作的正确 openmp 指令
- 如何在 <threads> c++ 中使用和一维数组进行矩阵乘法?
- C++按内存地址将多维数组更改为一维数组
- 在 c++ 中返回一维数组时出错
- 一维数组映射方式的性能差异问题
- 如何使用一维数组更改二维数组中的值?
- 使用二维数组作为一维数组是否正确?可能会导致未定义的行为左右?
- 将一维数组转换为二维数组
- 如何使用一维数组列表初始化二维数组
- 在一维数组中对二维进行排序
- 将一维数组的索引转换为二维数组
- 通过访问二维数组实现双线性插值的概念类似于一维数组
- 我对将数据从文件写入一维数组感到困惑
- 在一维数组中输出所有数据