当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;
}
网址:http://blog.sina.com.cn/s/blog_700a65cc0100mieb.html
#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;
}
网址:http://blog.sina.com.cn/s/blog_700a65cc0100mieb.html