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
也没有帮助。
摆脱该错误的最简单方法是什么?
解决方案
将 _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING 添加到预处理器定义中。
项目 -> 属性 -> C/C++ -> 预处理器 -> 预处理器定义。
这为我解决了这个问题。
推荐阅读
- javascript - 测试特定的数字序列是否在整数javascript中
- python - 如何在另一个矩阵中间插入一个矩阵
- r - R中是否有一个函数可以在时间记录中断之前读取最后30秒的时间?
- drools - 用于drools业务中心工作台的Nginx反向代理
- firebase - 如何从 Firebase 实时数据库中获取数据并使用 Flutter 将其放入列表中?
- webpack - 我在 Webpack 中收到 .css 模块解析失败错误,即使我已经在 module.rules 中有一个 css-loader
- python - Pandas Groupby 除了列并取该列的第一个值
- python - 有没有办法恢复 anaconda3 包含文件?
- python - Python Selenium:如何返回给定 URL 的所有 XPath 列表
- html - HTML:如何使用页面中文本的内部链接?