我尝试编写代码将二进制文件读入缓冲区,然后将缓冲区写入另一个文件。我有以下代码,但是缓冲区只存储文件中第一行的几个 ASCII 字符,没有其他内容。
int length;
char * buffer;
ifstream is;
is.open ("C:\\Final.gif", ios::binary );
// get length of file:
is.seekg (0, ios::end);
length = is.tellg();
is.seekg (0, ios::beg);
// allocate memory:
buffer = new char [length];
// read data as a block:
is.read (buffer,length);
is.close();
FILE *pFile;
pFile = fopen ("C:\\myfile.gif", "w");
fwrite (buffer , 1 , sizeof(buffer) , pFile );