文件读出来的结果和写入的结果不一样,请帮忙看一下
因为我要做一个图片拆分成4096字节后再发送的功能,现在遇到的问题是原图片的数据和拷贝出来的数据不一致,不知道是什么原因,请高手帮忙看下,谢谢了
int length;
char * buffer;
ifstream is;
is.open("E:\\test.JPG", ios::binary);
// get length of file:
is.seekg (0, ios::end);
length = is.tellg();
is.seekg (0, ios::beg);
unsigned char *ch = new unsigned char[length];
FILE *fp;
fp = fopen("E:\\test.JPG", "rb");
if (fp == NULL)
{
printf("file open failed");
}
fread(ch, length, 1, fp);
/////////////write file
AnsiString tempfilename = "E:\\test0.JPG";
FILE *stream;
if ((stream = fopen(tempfilename.c_str(), "w+")) == NULL)
{
fprintf(stderr, "Cannot open output file.\n");
return false;
}
fwrite(ch, length, 1, stream);
fclose(stream);
delete []ch;
//////////////write file
system("pause");