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

2023-12-14

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

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

我在 Windows 操作系统上使用 MingW 8.1.0 和 Clion 作为 IDE 并如本图所示https://en.cppreference.com/w/cpp/compiler_support好像 GCC 8.1 已经支持 std:filesystem

工具链配置

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

set(CMAKE_CXX_STANDARD 17)

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

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

并如本图所示https://en.cppreference.com/w/cpp/compiler_support好像 GCC 8.1 已经支持 std:filesystem

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将 std::filesystem 头文件添加到我的程序时出现编译错误 的相关文章

随机推荐