【问题标题】:std:: has no member "filesystem" in C++/17std:: 在 C++/17 中没有成员“文件系统”
【发布时间】:2020-09-24 08:44:43
【问题描述】:

我正在尝试包含<filesystem>,但是当我使用命名空间时,它会显示此错误:

std:: 没有成员“文件系统”

我知道以前是<experimental/filesystem>,命名空间是std::experimental::filesystem;

但是,当我这样做时,它也会给出这样的错误:

    #error The <experimental/filesystem> header providing std::experimental::filesystem is deprecated by Microsoft \
and will be REMOVED. It is superseded by the C++17 <filesystem> header providing std::filesystem. \
You can define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING to acknowledge that you have received this warning.

我使用的是 Visual Studio 2019,并且 C/C++ 语言设置已设置为最新版本。

那么是什么导致了这个问题?

编辑1:所有导致错误的代码:

#include <iostream>
#include <Windows.h>
#include <filesystem>

namespace fs = std::filesystem;

int main() {

    return 0;
}

编辑 2:所有旧代码,也有错误:

#include <iostream>
#include <Windows.h>
#include <experimental/filesystem>

namespace fs = std::experimental::filesystem;

int main() {


    return 0;

}

编辑 3:Visual Studio 2019 项目配置设置 -> 通用属性:

平台工具集:Visual Studio 2019 (v142) C++ 语言标准:ISO C++17 标准 (std::c++17) Windows SDK 10.0 版(最新安装的版本)

【问题讨论】:

  • 这可能是 Windows 的问题,而不是 C++ 的问题。您的 Windows 默认安装了 c++ 库,但 c++ 的版本可能不是 c++17。就是这样。
  • 我一直在使用文件系统库,而且我的编译器和你一样。您应该引用一些产生错误的实际代码。
  • 您需要启用 C++17 作为语言标准:Visual Studio 2019 C++ and std::filesystem
  • 在语言设置中我可以看到/设置 C++17 版本,但仍然有同样的问题
  • 请发帖minimal reproducible example。这是一个神秘的错误,只有在您尝试将 std::filesystem 用作类型或变量而不是命名空间时才会发生。

标签: c++ std-filesystem


【解决方案1】:

经过10个小时的奋斗,我得到了答案。我会发布它以供将来遇到同样问题的人使用;

在我的情况下,Visual Studio 配置设置仅在 x86 配置中设置,因此将配置设置为所有配置,而不是使用以下步骤:

1-项目属性->配置属性->通用->并将语言标准设置为“C++语言标准:ISO C++17标准(std::c++17)”

2- 项目属性 -> C/C++ -> 语言 -> 并将语言标准设置为“C++ Language Standart: ISO C++17 Standart (std::c++17)”

3-(最重要的)项目属性 -> C/C++ -> 命令行 -> 附加选项,粘贴:/Zc:__cplusplus

【讨论】:

  • 这对我有帮助。 Visual Studio 2022 的最后一步是什么?我们需要什么?
猜你喜欢
  • 2018-11-13
  • 1970-01-01
  • 2021-09-30
  • 1970-01-01
  • 2019-03-28
  • 2021-02-19
  • 1970-01-01
相关资源
最近更新 更多