您的位置:首页 > 编程语言 > C语言/C++

C++输出输入流复制文件

2015-01-03 09:53 281 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: