C++输入输出流方式复制文件。
// stream.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <fstream>
#include <iostream>
using namespace std;
int main( )
{
ofstream outfile;
outfile.open("d:/2.jpg", ios::binary);
ifstream infile;
infile.open ("c:/1.jpg", ios::binary );
infile.seekg (0, ios::end);
long length = infile.tellg();
infile.seekg (0, ios::beg);
const int BufferSize = 100;
char buffer[BufferSize];
while(1)
{
memset(buffer,0,sizeof(buffer));
infile.read (buffer,BufferSize);//从文件流中读取数据到buffer中
outfile.write(buffer,sizeof(buffer));
int curPos = infile.tellg();
printf("read->");
if (-1==curPos){
break;
}
}
return 0;
}