使用循环语句中,inti;i++;其中i增加到1000,不继续增加了,这种情况是什么原因,如何修改
int i = 0;
while (1)
{
if (oifs.eof())break;
oifs.getline(str, 500);
if (strstr(str, "/ ") != NULL)
{
sscanf(str, "/%d %d %lf", &(epoch[i].hour), &(epoch[i].min), &(epoch[i].sec));
cout << "" << epoch[i].hour <<" "<< epoch[i].min << " " << epoch[i].sec<< "" << endl;
}
i++;
}
文件内容超过1000行了么,没超过的话eof跳出循环了。
if (strstr(str, "/ ") != NULL)建议改为
char *s=strstr(str, "/ ") ;//定位到/所在位置。
if (s!= NULL)
sscanf(s, "/%d %d %lf", &(epoch[i].hour), &(epoch[i].min), &(epoch[i].sec));