猿问

fn为NULL值,为什么会这样?跟编译器有关吗?

void readfile()
{
ifstream ifile("city.txt",ios::in);//|ios_base::binary);
string fn;
int fx,fy,i=0;
if(ifile)
{
while(!ifile.eof())
{
ifile>>fn>>fx>>fy;
listArray[i].setname(fn);
listArray[i].setcpoint(fx,fy);
i++;
}
listSize=i;
display();
}
else cout<<"文件不存在!"<<endl;
ifile.close();
}
为了找原因,我用新建的txt试了一下,结果while里面还是会执行一次,结果fn为NULL值,fx和fy应该是地址值,为什么会这样?跟编译器有关吗?

陪伴而非守候
浏览 159回答 2
2回答

汪汪一只猫

char ch;while ((ch = getc()) != EOF)用这个方法.

HUX布斯

while(ifile.good())试试
随时随地看视频慕课网APP
我要回答