好的,我应该读取文件的一整行,然后遍历并将每一块单独划分到正确的分组中。以下是我到目前为止编写的代码。
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
我不知道零是从哪里来的..。请帮帮忙
发布于 2014-02-19 15:25:25
在继续处理之前,请检查largeString
是否为空。
while(!inFile.getline(largeString, LINE_SIZE, '\n').eof() && count < TEAMS)
{
if(largeString && largeString[0] != '\0')
{
next = 0;
...
...
}
}
正如Beta,建议你一定要研究一下stringstreams。
https://stackoverflow.com/questions/21873606
复制相似问题