我在 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 许可协议
我遇到了同样的问题,然后,当我删除了实验文件系统并添加了:
我会得到错误:
解决方案是转到项目属性并按照链接中的说明进行操作。 VS2017:E0135 命名空间“std”没有成员“文件系统”