我得到一个无限的循环,我不确定为什么或如何修复它
I get an infinite loop and i am not sure why or how to fix it
ifstream olympicsStream;
olympicsStream.open("olycs105.txt");
这是打开文件的地方
olympicsStream >> firstcountry; // string variable for countries
while (firstcountry!="END_OF_FILE")//
无法弄清楚在这里为条件放置什么
{
cout << firstcountry << endl;
olympicsStream >> a;
cout << a << endl;
for (i = 0; i < 5; i++)
{
olympicsStream >> namelast[i];
olympicsStream >> namefirst[i];
olympicsStream >> b[i];
olympicsStream >> c[i];
olympicsStream >> d[i];
getline(olympicsStream, Asport[i]);
}
cout << namelast[i - 1] << endl;
cout << namefirst[i - 1] << endl;
cout << b[i - 1] << endl;
cout << c[i - 1] << endl;
cout << d[i - 1] << endl;
cout << Asport[i - 1];
}
循环5行需要,但无限地使用相同的行,而不是通过文件的其余部分读取
您忘了在循环结束时更新变量'firstCountry'。
只需在关闭WILE循环之前添加olympicsStream >> firstcountry;
,并且您的代码应正常运行
假设文件中的最后一个单词是" end_of_file"
相关文章:
- 我不确定为什么代码没有运行,它在编译时抛出错误,说它无法找到 PrintArray()
- 获得访问违规的阅读位置,但不确定为什么
- 我不确定为什么我会为此获得输出?
- C++ 抛出读取访问冲突错误,但我不确定为什么。平铺滑块益智游戏
- 我一直得到一个期望;错误,我不确定为什么
- 尝试使用函数时会出现错误,不确定为什么
- 我得到一个无限的循环,我不确定为什么或如何修复它
- 在我的代码覆盖本身时遇到麻烦,我不确定为什么
- 不确定为什么这不返回元素的索引?
- 我不确定为什么我会从功能中获得此输出
- 学习左值和右值,但不确定为什么这个代码有效
- 默认情况下构造函数插入数据后,我没有得到任何输出,但我不确定为什么不
- 标识符"fill_vector"未找到,我不确定为什么
- 不确定为什么代码不能C++简单
- 不断得到分段错误:11,我不确定为什么
- C++考试修订版,不确定为什么正确答案是什么
- 我不确定为什么我会收到 NULL 指针取消引用错误
- 我不确定为什么我的 QThread 模式被阻塞
- 通过MCQ测试,我们不确定为什么这个函数原型会失败
- 我收到 [错误] 'Eintrag'没有命名类型,我不确定为什么