1 在C++11时,该类库定义在std::tr2::sys命名空间
#include<filesystem>
using namespace std;
using namespace std::tr2::sys;
//示例
void RemoveFile()
{
directory_iterator end, ite("aaa\\");
for (; ite != end; ++ite)
{
auto& thePath = ite->path();
if (!is_directory(thePath))
{
const string& sName = ite->path().filename();
if (sName == "test.txt")
{
remove(thePath);
}
}
}
}
2 上述代码在C++14中编译不过,已经不存在tr2命名空间
filesystem放在std::experimental::filesystem空间
#include <experimental/filesystem>
using namespace std::experimental::filesystem;
但是,在(VS2019,C++14)编译时可能会报错C1189,提示该头文件已被取

本文详细介绍了C++11、C++14和C++17中文件系统库的变化。从C++11的std::tr2::sys命名空间到C++14的std::experimental::filesystem,再到C++17标准的std::filesystem,演示了如何使用这些库进行文件和目录操作,如删除、检查文件类型、权限、大小等,并展示了代码示例和在不同标准下的编译注意事项。
最低0.47元/天 解锁文章
221

被折叠的 条评论
为什么被折叠?



