提供 std::experimental::filesystem 的标头已被 Microsoft 弃用,并将被删除,c++,visual-studio,visual-c++"/>

首页 > 解决方案 > C++ 一个 VS 错误:提供 std::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

也没有帮助。

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

标签: c++visual-studiovisual-c++

解决方案


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

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

这为我解决了这个问题。


推荐阅读