cin>>n;
file.write((char *)&n,sizeof(int));
......
(1)
while(!file.eof())
{
file.read((char *)&n,sizeof(int));
cout<<n;
}
(2)
file.read((char *)&n,sizeof(int));
while(!file.eof())
{
file.read((char *)&n,sizeof(int));
cout<<n;
}(1)中当输入n后,输出时为什么会输出2次n?(2)却能得期望的结果?
file.write((char *)&n,sizeof(int));
......
(1)
while(!file.eof())
{
file.read((char *)&n,sizeof(int));
cout<<n;
}
(2)
file.read((char *)&n,sizeof(int));
while(!file.eof())
{
file.read((char *)&n,sizeof(int));
cout<<n;
}(1)中当输入n后,输出时为什么会输出2次n?(2)却能得期望的结果?
条件,当然要输出两次了
file.read((char *)&n,sizeof(int));
while(!file.eof())
{
cout < <n;
file.read((char *)&n,sizeof(int));
}