将图像等文件转为二进制数据再输出实现复制

#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;
}


 
 
 

猜你喜欢

转载自blog.csdn.net/u014080185/article/details/71170616