【发布时间】:2017-10-24 18:55:40
【问题描述】:
我一直在尝试使用循环读取文本文件。但由于某种原因,它似乎永远不会使整数值正确。我总是以垃圾值告终。
while(!file.eof()) // I've also tried other variations of this while loop, none of which worked either
{
// ifstream, string, char, string, int
file >> name >> sex >> data >> score;
std::cout << name << std::endl;
if (sex == 'F')
{
femaleAverage += score;
femaleCount++;
}
else
{
maleAverage += score;
maleCount++;
}
if (data.compare("CC"))
{
comAverage += score;
comCount++;
}
else
{
uniAverage += score;
uniCount++;
}
}
文本文件如下所示:
Bailey M CC 68
Harrison F CC 71
Grant M UN 75
Peterson F UN 69
Hsu M UN 79
Bowles M CC 75
Anderson F UN 64
Nguyen F CC 68
Sharp F CC 75
Jones M UN 75
McMillan F UN 80
Gabriel F UN 62
【问题讨论】:
-
你的输出是什么样的?
标签: c++ file text file-io text-files