码迷,mamicode.com
首页 > 编程语言 > 详细

c++ 拷贝资源方法

时间:2016-02-21 22:38:54      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:

#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;

}

c++ 拷贝资源方法

标签:

原文地址:http://www.cnblogs.com/HemJohn/p/5205637.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!