读写二进制文件
我正在尝试编写代码将二进制文件读入缓冲区,然后将缓冲区写入另一个文件。我有以下代码,但缓冲区只存储文件中第一行的几个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 );