所以我有一个包含团队和分数的文件,我需要将团队读入一个二维字符数组,然后将他们的分数读入一个整数数组。
这是我当前的函数代码,如何在团队名称完成后停止阅读,然后将分数存储在单独的数组中?
void getData (char array [][COLS], int rows, int scores [])
{
ifstream inFile; //Input file stream object
//Open the file
inFile.open ("scores.txt");
if (!inFile)
{
cout << "Error opening data file!\n";
exit(102);
}
for (int r = 0; r < rows; r++)
{
{
//reads through columns
for (int c = 0; c < COLS; c++)
{
inFile >> array[r][c];
}
}
}
for (int count = 0; count < ROWS; count++)
{
for(int i = 0; i < COLS; i++)
{
cout << array[count][i];
}
}
inFile.close();
}
我的输入文件如下:
Jaquars 23
Colts 23
49ers 13
Lions 13
Titans 7
Redskins 38
Cardinals 14
Buccaneers 36
Seahawks 30
Lions 24
Bears 28
Packers 23
Bears 14
Rams 22
Texans 6
Packers 34