您的位置:首页 > 其它

fstream 的用法——文件拷贝

2016-01-13 09:14 155 查看
转自 http://blog.sina.com.cn/s/blog_700a65cc0100mieb.html
当ifstream read到文件尾,返回0值,其它时候返回非0值。下面给出一个用C++标准库实现文件拷贝的函数:

#include<iostream>

#include<fstream>

#include<string>

usingnamespace std;

constint BUFSIZE
= 1024 * 1024;

void CopyRawFile(string
InFile, string OutFile)

{

char*
pchar = newchar[BUFSIZE];

ofstream
ofile;

ifstream
ifile;

ofile.open(OutFile.c_str(),
ios::binary);

ifile.open(InFile.c_str(),
ios::binary);

while(ifile.read(pchar,
BUFSIZE))

ofile.write(pchar,
BUFSIZE);

ofile.write(pchar,
ifile.gcount());

ifile.close();

ofile.close();

delete []pchar;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: