我有一个看起来像这样的文本文件:
Azrin, Neil
2.3 6.0 5.0 6.7 7.8 5.6 8.9 7.6
Babbage, Charles
2.3 5.6 6.5 7.6 8.7 7.8 5.4 4.5
它继续为 24 个不同的名称。名字在第一行,数字在文件的第二行。第一个数字是潜水的难度级别,后面的7个数字是7位不同评委给出的分数。
我已经能够读取潜水员的姓名和难度级别,但它不会读取难度级别之后的分数。
我已经尝试了几乎所有我能想到的让它正常工作,有人可以帮忙吗?
到目前为止,我将数据读入结构的代码如下所示
const int NUM_NAMES = 24;
const int NUM_SCORES = 7;
const int NUM_ROUNDS = 2;
typedef double scoreTable[NUM_ROUNDS] [NUM_SCORES];
typedef double difficultyList[NUM_ROUNDS];
struct diveInfo
{
string diversName;
double totalScore;
double diveTotal;
difficultyList diff;
scoreTable scores;
};
typedef diveInfo diverList[NUM_NAMES];
int main()
{
diveInfo record;
diveInfo * ptr;
ptr = &record;
int lcv;
ifstream inFile;
inFile.open ("diveData.txt");
if (!inFile)
{
cout << "ERROR: File could not be opened" << endl << endl;
exit (EXIT_FAILURE);
}
for (lcv = 0; lcv < NUM_NAMES; lcv++)
getline(inFile, ptr[lcv].diversName);
delete ptr;
ptr = new diveInfo;
inFile >> *ptr[lcv].diff;
delete ptr;
ptr = new diveInfo[NUM_SCORES];
inFile >> *ptr[lcv].scores; // here is the problem
return (EXIT_SUCCESS);
}