C++ 将文本文件中的数据读入struct,然后打印数据

C++ 将文本文件中的数据读入struct,然后打印数据,c++,C++,嘿,伙计们,我正在写一个程序,从文件中读入数据并将其存储在结构中,我有几个问题。文本文件如下所示: 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 尼尔·阿兹林 2.3 6.0 5.0 6.7 7.8 5.6 8.9 7.6 巴贝奇,查尔斯 2.3 5.6 6.5 7.6 8.7 7.8 5.4 4.5

嘿,伙计们,我正在写一个程序,从文件中读入数据并将其存储在结构中,我有几个问题。文本文件如下所示:

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 尼尔·阿兹林 2.3 6.0 5.0 6.7 7.8 5.6 8.9 7.6 巴贝奇,查尔斯 2.3 5.6 6.5 7.6 8.7 7.8 5.4 4.5 行中的第一个数字是难度等级,接下来的7个数字是分数,接着是24个不同的名字

我的程序将打印所有潜水员的名字,然后是难度等级。然后它将只打印潜水员1的第一个分数,而不是所有分数

此外,对于潜水员#2的分数,它打印第二个分数(第三行数字),而不是第一个分数(第二行数字)。对每个潜水员都是如此

我怎样才能让它读取并打印每个潜水员的所有分数

我已经为此工作了几个小时,所以非常感谢您的帮助

我的代码:

for (lcv = 0; lcv < NUM_NAMES; lcv++)                    //reads in all of the data
{
getline(inFile, diveList[lcv].diversName);

inFile >> diveList[lcv].diff;

for (count = 0; count < NUM_SCORES; count++)
{
inFile >> diveList[lcv].scores[count];              //the problem may be here on down below where i print out the data... im not sure
}

inFile.ignore(200, '\n');

}

printTableOne (diveList);




void printTableOne (const diverList diveList)
{
int lcv;
int count = 0;
cout << "The number of divers for round 1 is: " << NUM_NAMES << endl << endl;

for (lcv = 0; lcv < NUM_NAMES; lcv++)
{

cout << "Diver #" << lcv << endl;
cout << setprecision(1) << fixed <<  endl;
cout << "NAME: " << diveList[lcv].diversName << endl;
cout << "DIFFICULTY LEVEL: " << diveList[lcv].diff << endl;
cout << "SCORES: " << diveList[lcv].scores[lcv] << endl;     //problem here??

cout << endl << endl;
}
for(lcv=0;lcv>diveList[lcv].diff;
对于(计数=0;计数>diveList[lcv].分数[count];//问题可能就在下面我打印数据的地方……我不确定
}
忽略(200,“\n”);
}
打印表一(diveList);
无效打印表一(常量列表diveList)
{
国际lcv;
整数计数=0;

这个问题确实是在所难免的

cout << "SCORES: " << diveList[lcv].scores[lcv] << endl;

cout您预计会发生什么以及会发生什么?您尝试过调试/穷人的打印调试器吗?同样的?感谢您的回答我尝试过设置for循环:for(count=0;count