电子请柬免费制作:救急啊`~愁死我了`~read()之后文件指针傻了 T_T

来源:百度文库 编辑:高考问答 时间:2024/04/29 21:34:07
下面是我写的一函数 能编译 但有iofil.read((char*)&std,sizeof(Student));
这句 文件tellg()就一直指在-1 注销这句文件指针就能正常移动了
我想了半天都想不明白 高手帮我啊5555555555

int Student::readData(char *nanu)
{
int address;
Student std;
fstream iofil("stuData",ios::in|ios::out);
iofil.seekg(0,ios::end);
int nore=iofil.tellg()/sizeof(Student);
for(int pos=1;pos<=nore;pos++)
{//cout<<pos<<endl;

iofil.seekg((pos-1)*sizeof(Student),ios::beg);
//cout<<(pos-1)*sizeof(Student)<<endl;
//cout<<sizeof(Student)<<endl;
iofil.read((char*)&std,sizeof(Student));
cout<<"xxx"<<iofil.tellg()<<endl;
//cout<<pos<<endl;

if(strcmp(std.name,nanu)==0||strcmp(std.stuNum,nanu)==0||strcmp(std.address,nanu)==0)
{
std.printData(3,3,1);
break;
}
}
iofil.close();
return 0;
}
忘了说了是C++的

你写的有点复杂不是很明白还是高手来顶一下吧

代码太少,看得不是很明白
查一下tellg函数吧