C VS 错误:提供 std::experimental::filesystem 的 <experimental/filesystem> 标头已被 Microsoft 弃用并将被删除

新手上路,请多包涵

我在 Visual Studio (Windows 10) 上用 C++ 编码并得到这个错误:

 #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.

有了这个标题:

 #include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
#include <filesystem>//If I will disable it nothing happens.

#include <experimental/filesystem> //If I will disable it happens another error.
namespace fs = std::experimental::filesystem;

using namespace std;

我试过: #define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING 在主 cpp 文件中。它没有帮助。

那么我从 这里 粘贴这段代码:

 #ifdef __cpp_lib_filesystem
    #include <filesystem>
    using fs = std::filesystem;
#elif __cpp_lib_experimental_filesystem
    #include <experimental/filesystem>
    using fs = std::experimental::filesystem;
#else
    #error "no filesystem support ='("
#endif

也没有帮助。

摆脱该错误的最简单方法是什么?

原文由 Jenia 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 2.2k
2 个回答

我遇到了同样的问题,然后,当我删除了实验文件系统并添加了:

 #include <filesystem>
namespace fs = std::filesystem;

我会得到错误:

命名空间“std”没有成员“文件系统”

解决方案是转到项目属性并按照链接中的说明进行操作。 VS2017:E0135 命名空间“std”没有成员“文件系统”

原文由 Do0Nnie 发布,翻译遵循 CC BY-SA 4.0 许可协议

将 _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING 添加到预处理器定义中。

项目 -> 属性 -> C/C++ -> 预处理器 -> 预处理器定义。

这为我解决了这个问题。

原文由 Spark 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题