嗨,我有以下循环阅读:
void personFin(vector<Person>* persvect, string filename)
{
ifstream personfile(filename);
string name;
int lhstrength;
int rhstrength;
int erasiveskill;
int ID = 1;
cout << "reading in persons" << endl;
if (personfile.good())
{
while (!(personfile >> name).eof())
{
cout << "start read in " << ID << endl;
personfile >> lhstrength;
personfile >> rhstrength;
personfile >> erasiveskill;
Person temp(name, lhstrength, rhstrength, erasiveskill, ID);
persvect->push_back(temp);
cout << "end read in " << ID << endl;
ID++;
}
personfile.close();
}
else
{
cout << "ERROR: Cannot open file.\n";
}
}
我在Xcode中执行了我的程序,当我使用g ++编译它时一切正常,输入文件循环是无限的
感谢您的帮助