小编Ken*_*tro的帖子

C ++ 17文件系统copy_file访问被拒绝

我正在使用 Visual Studio 2017,运行 c++17 ISO 标准(不是 boost)设置为能够使用<filesystem>. 不过,我遇到了麻烦,因为每次运行时,无论是在调试还是发布中,file_copy()都会出现访问被拒绝的错误。我检查了代码的其他部分,唯一不起作用的是file_copy(). 有谁知道我为什么会收到此错误以及如何修复它?我是我电脑上的管理帐户。

std::vector<std::string> findAndCopyFiles()
{
    std::vector<std::string> fileNames;
    std::error_code errCode;
    errCode.clear();

    fs::current_path("C:\\Users\\kenny\\Desktop\\Engine", errCode);
    std::cout << errCode.message() << std::endl; errCode.clear();

    fs::path pa = fs::current_path();
    pa += "\\TEMP";
    std::cout << pa.string() << std::endl;

    if (fs::create_directory(pa, errCode))//Create directory for copying all files)
    {
        std::cout << "Directory created successfully" << std::endl;
        std::cout << errCode.message() << std::endl; errCode.clear();
    }
    fs::path tempDir(pa);
    fs::path currentDirectory = fs::current_path();
    fs::recursive_directory_iterator dirIter(currentDirectory);
    for (auto &p : dirIter) …
Run Code Online (Sandbox Code Playgroud)

c++ filesystems c++17

-1
推荐指数
1
解决办法
2646
查看次数

标签 统计

c++ ×1

c++17 ×1

filesystems ×1