C++ stl 复制文件的方法
2008-11-13 16:40
337 查看
头文件
#ifndef ioshelperH
#define ioshelperH
#include <fstream>
#include <vcl.h>
//---------------------------------------------------------------------------
class IOHelper
{
public:
void CopyFiles(char* srcPath, char* destPath);
};
#endif
======================================================
源码
void IOHelper::CopyFiles(char* srcPath, char* destPath)
{
//using namespace std;
ifstream src(srcPath, ios::binary | ios::in);
if (src.fail()) {
//"file src does not exist"
return;
}
ofstream dest(destPath, ios::out | ios::binary | ios::app);
char buffer[32767];
//获取文件大小
//int filesize;
//src.seekg(ios::beg, ios::end);
//filesize = src.tellg();
src.seekg(ios::beg);
dest.seekp(0);
while (src.good())
{
memset(buffer, 0, sizeof(char) * 32767);
src.read(buffer, 32767);
dest.write(buffer, src.gcount());
if (src.gcount() < 32767)
break;
}
}
#ifndef ioshelperH
#define ioshelperH
#include <fstream>
#include <vcl.h>
//---------------------------------------------------------------------------
class IOHelper
{
public:
void CopyFiles(char* srcPath, char* destPath);
};
#endif
======================================================
源码
void IOHelper::CopyFiles(char* srcPath, char* destPath)
{
//using namespace std;
ifstream src(srcPath, ios::binary | ios::in);
if (src.fail()) {
//"file src does not exist"
return;
}
ofstream dest(destPath, ios::out | ios::binary | ios::app);
char buffer[32767];
//获取文件大小
//int filesize;
//src.seekg(ios::beg, ios::end);
//filesize = src.tellg();
src.seekg(ios::beg);
dest.seekp(0);
while (src.good())
{
memset(buffer, 0, sizeof(char) * 32767);
src.read(buffer, 32767);
dest.write(buffer, src.gcount());
if (src.gcount() < 32767)
break;
}
}
相关文章推荐
- vs2015中复制C++ DLL 和.pdb文件到C#工程中bin目录的设置方法
- C++ 复制文件的n种方法
- C++文件复制方法总结
- C++ STL VC 最简单的按行读取文件方法
- C++ MFC 文件操作(新建,删除,剪切,复制,读数据,写数据,重命名)
- c++项目包含纯c文件编译方法
- 【C++】变量定义在.h头文件导致 multiple definition of 的解决方法和根本原因
- php不使用copy()函数复制文件的方法
- 系统不能复制粘贴文件的方法
- php不使用copy()函数复制文件的方法
- java高效的文件复制方法
- Win7复制文件时出现:“您需要权限来执行操作!”(终极解决方法!)
- IO(六、)复制文件方法一:一个字符一个的读写
- 用C++访问DBF文件的方法
- Java IO学习【13】利用字节流复制文件的4种方法详解
- windows 与linux 下用C++读取sqlite实现文件复制(一)
- windows 与linux 下用C++读取sqlite实现文件复制(三)
- C/C++多种方法获取文件大小
- C++ STL 迭代器方法 之 advance与prev 方法 浅析
- C和C++获取文件大小的方法总结