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;
}
当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;
}
相关文章推荐
- 局部二值化
- objective-c 中数据类型之中的一个 几何数据类型(CGPoint,CGSize,CGRect)
- "类型初始值设定项引发异常"
- BroadcastReceiver的区别细究
- 平面YUV422转平面RGB24 平面YUV420转平面YUV422 平面YUV420转RGB24
- C++中const关键字详解
- win10安装tomcat遇到的小问题
- 设计模式笔记--装饰模式
- Extjs学习----------动态载入js文件(减轻浏览器的压力)
- 商务英语句型11
- Quick-Cocos2dx-- 资源热更新2
- 紫金桥组态软件的DL/T 645-2007驱动
- ES6学习——类语法:Symbol.species在实例创建中的应用
- 在基于tomcat的web project中加载dll文件的方法(来源于实际项目经验)
- KMP算法
- meaven 下载Jar包
- 查看oracle数据库的连接数以及用户
- git学习笔记
- linux生产服务器有关网络状态的优化措施
- 七分养护三分维修 关注车辆的生命周期保养