当我尝试在 vs 2019 中使用 std::filesystem 时出现错误

when I try and use std::filesystem in vs 2019 I get an error

我使用的是 Microsoft Visual Studio 2019,每当我键入 std::filesystem 时,“文件系统”下就会出现一个红色条,其中包含消息

namespace "std" has no member "filesystem"

name followed by '::' must be a class or namespace name

当我前面没有“::”和分别有时。

我已经包含了文件系统,所以我不明白为什么它不起作用。

我希望我提供了足够的信息,如果没有请在评论中提问。如果你帮不了我,也许你可以帮我找到 std::filesystem::recursive_directory_iterator.

的替代方案

C++17中添加了filesystem库,VS2019默认以C++14模式启动。

  • 打开Project\<project name> Properties
  • Select Configuration Properties\General
  • 右侧有一个名为 C++ Standard 的字段,select 其中之一:
    • ISO C++17 标准 (/std:c++17)
    • 预览 - 来自最新 C++ 工作草案的特性 (/std:c++latest)

然后 #include <filesystem> 就可以开始了。