3

我正在尝试编译一个包含 std::filesytem 头文件的简单 C++ 程序!

#include <iostream>
#include <filesystem>

int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

编译时出现以下错误

In file included from C:/PROGRA~1/MINGW-~1/X86_64~2.0-W/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/filesystem:37,
                 from C:\Users\{User}\CLionProjects\untitled3\main.cpp:2:
C:/PROGRA~1/MINGW-~1/X86_64~2.0-W/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h: In member function 'std::filesystem::__cxx11::path& std::filesystem::__cxx11::path::operator/=(const std::filesystem::__cxx11::path&)':
C:/PROGRA~1/MINGW-~1/X86_64~2.0-W/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:237:47: error: no match for 'operator!=' (operand types are 'std::filesystem::__cxx11::path' and 'std::filesystem::__cxx11::path')
    || (__p.has_root_name() && __p.root_name() != root_name()))
                               ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~

我在使用 MingW 8.1.0 和 Clion 作为 IDE 的 Windows 操作系统上,正如https://en.cppreference.com/w/cpp/compiler_support上所描述的,似乎 GCC 8.1 已经支持 std:fileystem

工具链配置

编辑:语言级别在我的 CMakeList 中设置,如下所示

set(CMAKE_CXX_STANDARD 17)
4

1 回答 1

3

我在使用 MingW 8.1.0 和 Clion 作为 IDE 的 Windows 操作系统上

我最近才实现了 MinGW 支持std::filesystem,它在 GCC 8 中不存在。它目前仅在 GCC 颠覆主干中可用。

并且正如https://en.cppreference.com/w/cpp/compiler_support上所描述的,GCC 8.1 似乎已经支持 std:fileystem

仅适用于非 Windows 平台。Windows 支持与 POSIX 支持非常不同,需要做很多额外的工作。

于 2018-09-20T15:08:56.413 回答