关于网友提出的“ 读文件问题?”问题疑问,本网通过在网上对“ 读文件问题?”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: 读文件问题?
描述: void read_data()
{
ifstream infile(filename);
if(!infile)
{
cout<<"open cerr!";
return ;
}
int n;
infile.read((char*)&n,sizeof(n));
while(n>0)////读取文件!infile.eof()
{
end->next=new link;
end=end->next;
end->next=NULL;
infile.read((char*)&end->worker,sizeof(end->worker));
n--;
}
infile.close();
}
int n;
infile.read((char*)&n,sizeof(n));
上面这段话是什么意思??
解决方案1: 32位系统中1个int长度为4Byte,64位是8Byte
所以,infile.read((char*)&n,sizeof(n));
含义是,读取4或8Byte数据并保存到变量n的空间中去。
建议赋好初值:int n=0;
解决方案2: 二进制文件的读,按一个字节的方式逐字节读取吧,读取后文件指针后移。
以上介绍了“ 读文件问题?”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/2675880.html