将 std::文件系统头文件添加到我的程序时出现编译错误

Compile error when std::filesystem header file is added to my program

本文关键字:程序 编译 错误 我的 文件系统 std 文件 添加      更新时间:2023-10-16

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

#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}CLionProjectsuntitled3main.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()))
~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~

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

工具链配置

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

set(CMAKE_CXX_STANDARD 17)

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

我最近才实现了对std::filesystem的 MinGW 支持,它在 GCC 8 中不存在。它目前仅在 GCC Subversion 中继中可用。

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

仅适用于非 Windows 平台。Windows支持与POSIX支持非常不同,并且需要大量额外的工作。