好的,所以我应该阅读文件的整行,然后单独将每个部分分成正确的分组。这是我到目前为止编写的代码。
while(!inFile.getline(largeString, LINE_SIZE, '\n').eof() && count < TEAMS)
{
next = 0;
next = buildStruct(largeString, smallString, next);
strcpy(stats[count].name, smallString);
cout << stats[count].name << endl;
next = buildStruct(largeString, smallString, next);
stats[count].wins = atoi(smallString);
cout << stats[count].wins << endl;
next = buildStruct(largeString, smallString, next);
stats[count].losses = atoi(smallString);
cout << stats[count].losses << endl;
next = buildStruct(largeString, smallString, next);
stats[count].overtime_losses = atoi(smallString);
cout << stats[count].overtime_losses << endl;
count++;
}
这是我文件的内容
Brookings 12 24 7
Aberdeen 22 16 2
Austin 28 11 1
Bismark 24 13 4
Minot 18 21 3
这是我从编译器中获得的
Brookings
12
24
7
0
0
0
Aberdeen
22
16
2
我不知道零来自哪里......请帮忙
答案 0 :(得分:0)
在进行处理之前,请检查largeString
是否为空。
while(!inFile.getline(largeString, LINE_SIZE, '\n').eof() && count < TEAMS)
{
if(largeString && largeString[0] != '\0')
{
next = 0;
...
...
}
}
作为Beta,建议您一定要查看字符串流。