1. 程式人生 > >將影象等檔案轉為二進位制資料再輸出實現複製

將影象等檔案轉為二進位制資料再輸出實現複製

#include <fstream>
#include<iostream>
#include <stdio.h>
using namespace std;

int main()
{
	char buf[1024];

	FILE* rfile;
	FILE* wfile;
	rfile = fopen("1.jpg","rb");           // 複製影象,也可以複製任意檔案
	wfile = fopen("2.jpg", "wb");

	cout << "開始複製" << endl;

	while (!feof(rfile))
	{
		memset(buf, 0, sizeof(buf));
		size_t readlen = fread(buf, sizeof(char), sizeof(buf), rfile);
		size_t writelen = fwrite(buf, sizeof(char), readlen, wfile);
	}

	fclose(rfile);
	fclose(wfile);

	cout << "done" << endl;
}