文件内容如下:
zwj m 199109 zj computer softwear 2011 1 312011080611101
zhy f 199202 zj computer softwear 2011 1 312011080611102
cxn m 199209 fj computer softwear 2011 1 312011080611103
ycx m 199204 sc computer softwear 2011 1 312011080611104
wxq f 199008 sc computer softwear 2011 1 312011080611105
hl m 199105 sc computer softwear 2011 1 312011080611106
qzk m 199105 sc computer softwear 2011 1 312011080611107
yl m 199210 sc computer softwear 2011 1 312011080611108
tjh f 198707 sc hospital madicine 2008 2 312011080611178
代码如下
while(!infile.eof())
{
infile>>na;student[i].SetDate1(na);cout<<na<<' ';
infile>>s;student[i].SetDate2(s);cout<<s<<' ';
infile>>bir;student[i].SetDate3(bir);cout<<bir<<' ';
infile>>home;student[i].SetDate4(home);cout<<home<<' ';
infile>>aca;student[i].SetDate5(aca);cout<<aca<<' ';
infile>>ma;student[i].SetDate6(ma);cout<<ma<<' ';
infile>>gra>>cla;student[i].SetDate7(gra,cla);cout<<gra<<' '<<cla<<' ';
infile>>num;student[i].SetDate8(num);cout<<num<<endl;
i++;
}
infile.close;
还是没理解好多一行空白的意思,我文件里没有空白....那觉得该怎么改才好呢?
追答改用for控制 看结果对不对
追问还是不对。条件是 for(i=0;!infile.eof();i++)
追答用个cout 纪录有几次~~就知道问题了
printf 出来 看每次写出的顺序