gpt4 book ai didi

c++ - 不同编译器中的 std::filesystem 和 std::experimental::filesystem 问题

转载 作者:行者123 更新时间:2023-11-28 01:21:51 30 4
gpt4 key购买 nike

我正在编写一个利用 std::filesystem 的库(仅供学习)。它在 MSVC 上运行良好,但是默认情况下,Linux 的 LTS 版本就像 Ubuntu 一样附带 GCC 6.x,官方存储库中的 clang 是 3.8,它没有 std::filesystem 而我必须使用 std::experimental::filesystem。我该如何解决这个问题,以便我可以支持 GCC 6、GCC 8+(std::filesystem 工作的地方)、Clang 3.8、最新的 Clang 和 MSVC?我正在使用 CMAKE 作为我的构建系统

最佳答案

条件编译可能有帮助:

#if(defined(_MSC_VER) or (defined(__GNUC__) and (7 <= __GNUC_MAJOR__)))
using n_fs = ::std::filesystem;
#else
using n_fs = ::std::experimental::filesystem;
#endif

关于c++ - 不同编译器中的 std::filesystem 和 std::experimental::filesystem 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55782902/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com