主题:求助!关于读入二进制文件的问题
#include<fstream.h>
void main()
{
ifstream infile;
ofstream outfile;
char data;
int npels=0;
infile.open("LENA256.img",ios::binary);
outfile.open("t.txt");
while (!infile.eof())
{
infile>>data;
outfile<<(int)((unsigned char)data)<<" ";
npels++;
if (npels%256==0) outfile<<"\n";
}
infile.close();
outfile.close();
}
运行之后发现读入的数据少了很多个,在输出文件outfile中发现开始读入正常,但后来就开始读漏一些数了。究竟是为什么啊,求助!
void main()
{
ifstream infile;
ofstream outfile;
char data;
int npels=0;
infile.open("LENA256.img",ios::binary);
outfile.open("t.txt");
while (!infile.eof())
{
infile>>data;
outfile<<(int)((unsigned char)data)<<" ";
npels++;
if (npels%256==0) outfile<<"\n";
}
infile.close();
outfile.close();
}
运行之后发现读入的数据少了很多个,在输出文件outfile中发现开始读入正常,但后来就开始读漏一些数了。究竟是为什么啊,求助!