如何将文件从文件夹复制到另一个文件夹 [英] How to copy a file from a folder to another folder

查看:250
本文介绍了如何将文件从文件夹复制到另一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用C ++将文件从一个文件夹复制到另一个文件夹?

How do I copy a file from one folder to another folder using C++?

推荐答案

#include <fstream>

// copy in binary mode
bool copyFile(const char *SRC, const char* DEST)
{
    std::ifstream src(SRC, std::ios::binary);
    std::ofstream dest(DEST, std::ios::binary);
    dest << src.rdbuf();
    return src && dest;
}

int main(int argc, char *argv[])
{
    return copyFile(argv[1], argv[2]) ? 0 : 1;
}

它掩盖了一些潜在的复杂问题:错误处理,文件名字符编码。但可以给你一个开始。

it glosses around some potentially complicated issues: error handling, filename character encodings... but could give you a start.

这篇关于如何将文件从文件夹复制到另一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆