1.语言标准要设置 C++17
请添加图片描述
2.代码

#include<iostream>
#include<windows.h>
#include <filesystem>
using namespace std;

int main()
{
    char src[260] = { 0 };
    char des[260] = { 0 };
    cout << "输入原文件路径:";
    cin >> src;
    cout << "输入目标文件路径:";
    cin >> des;
	try
	{
		std::filesystem::copy(src, des, std::filesystem::copy_options::recursive);
	}
	catch (const std::exception&)
	{
        cout << "文件复制失败" << endl;
        return 0;
	}
    cout << "文件复制成功" << endl;

}

核心函数
copy();
详情参考链接

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐