zoukankan      html  css  js  c++  java
  • c++ 拷贝资源方法

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

    }

  • 相关阅读:
    npm改为淘宝镜像
    html中table中td内容换行
    git 切换文件夹路径
    git经常使用的命令
    day16
    day15
    day13
    day14
    day12
    day11
  • 原文地址:https://www.cnblogs.com/HemJohn/p/5205637.html
Copyright © 2011-2022 走看看