解释为什么它不返回它应该返回的内容
Explanation why it doesn't return what it should
我有一个从文件"Curent.txt"获取学生信息的功能。
这是结构:
struct students {
string CodSt;
string NumeSt;
string PrenSt;
string DenDisc1;
string MedCD1;
string DenDisc2;
string MedCD2;
string DenDisc3;
string MedCD3;
} student[50];
这就是函数:
void getStudents() {
int i = 0;
ifstream ifs("Curenta.txt");
while(!ifs.eof()) {
ifs >> student[i].CodSt >> student[i].NumeSt >> student[i].PrenSt >> student[i].DenDisc1
>> student[i].MedCD1 >> student[i].DenDisc2 >> student[i].MedCD2 >> student[i].DenDisc3
>> student[i].MedCD3;
if(!ifs.eof()) {
i++;
cout << i;
}
var = i;
ifs.close();
}
而在"库伦特.txt"中,我只有这个:
9 8 1 1 6 1 1 1 1
3 1 1 1 4 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 7 1 1 1 1
我的问题是为什么当我输出变量"i"时,值只有 1。
提前谢谢。
读取完所有数据后,您应该关闭inputstream
,因此不在循环中,而不是在循环中。
相关文章:
- 是否可以解释为什么这会返回 21
- 解释通过从函数引用返回数组的语法
- 解释为什么它不返回它应该返回的内容
- 有人可以解释一下'sizeof'在此代码中返回的结果吗
- 有人可以向我解释什么[](int i){返回i%2 == 0;} 方法
- 返回指针的语句 - 解释它是如何工作的以及为什么
- ob->我应该返回 ob "this" 的地址,但它返回 i ,任何解释?
- 有人可以向我解释为什么我的函数返回 0 而不是 1
- C 如何解释System()的返回值
- 解释C 中三种返回类型的方法
- RVO(返回值优化)无法解释这个谜团
- 众所周知,构造函数没有返回类型,但在下面的代码中,构造函数正在返回..任何人都能解释吗
- 返回模的解释
- 请解释这段代码(返回语句)
- 有人能向我解释一下为什么sizeof函数在下面的代码中返回不同的值
- 为什么QVariant::type()返回一个QVariant::type,而它应该被解释为QMetaType:: ty
- 有人能解释一下这些函数返回类型的区别吗?
- 即使字符串相同,c++ STRCMP也返回0.请解释一下原因
- 调用返回类型不完整的方法和无法解释的模板解决方案
- 解释此C++函数如何返回数组