Mingw错误?:std :: filesystem :: copy在文件存在时失败,并出现文件系统错误,即使定义了overwrite_existing的copy_option

问题描述

MINGW 8.0版
-C编译器标识为GNU 10.2.0
-CXX编译器标识为GNU 10.2.0
-检查可运行的C编译器:P:/MSYS2/mingw64/bin/gcc.exe
-检查工作的C编译器:P:/MSYS2/mingw64/bin/gcc.exe-有效

尝试运行:


#include <iostream>
#include <fstream>
#include <filesystem>

namespace fs = std::filesystem;

constexpr auto * f1 ="C:\\TEMP\\fred_test.txt";
constexpr auto * f2 ="C:\\TEMP\\fred_test.txt~";

void create_file(char const* p){
    std::ofstream ofs1{p};
}

int main() {
    try{
        fs::remove(f1);
        fs::remove(f2);
        create_file(f1);
        create_file(f2);
        fs::copy_file(f1,f2,fs::copy_options::overwrite_existing);
        std::cout << "success" << std::endl;
    } catch (fs::filesystem_error const& fe) {
        std::cout << fe.what() << std::endl;
    }
}

给出以下输出


filesystem error: cannot copy file: File exists [C:\TEMP\fred_test.txt] [C:\TEMP\fred_test.txt~]

使用msvc:


success

使用以下命令运行CMake:P:\ MSYS2 \ mingw64 \ bin \ cmake.exe -DCMAKE_BUILD_TYPE = Debug -G“ CodeBlocks-MinGW Makefiles” C:[***] \ test_fs


cmake_minimum_required(VERSION 3.17)
project(test_fs)
set(CMAKE_CXX_STANDARD 20)
add_executable(test_fs main.cpp)

有人还能复制吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)