标签:
#include "stdio.h"
#include "stdlib.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <dirent.h>
bool copyFile(const std::string & targetPath,const std::string & sourcePath)
{
if(targetPath.empty() || sourcePath.empty())
return false;
FILE * read_fp = fopen(targetPath.c_str(),"rb");--使用二进制读取
if(!read_fp)
return false;
fseek(read_fp,0,SEEK_END);
size_t size = ftell(read_fp);
fseek(read_fp,0,SEEK_SET);
unsigned char* buffer = new unsigned char[size];
fread(buffer,sizeof(unsigned char),size,read_fp);
fclose(read_fp);
if(nullptr == buffer)
return false;
FILE * write_fp=fopen(targetPath.c_str(),"wb+");//拷贝
fwrite(buffer, sizeof(unsigned char),size,write_fp);
fclose(write_fp);
return true;
}
标签:
原文地址:http://www.cnblogs.com/HemJohn/p/5205637.html