半个多月前,就有消息说 msvc 将要支持 std::filesystem 了,后来更新 VisualCppTools Daily 发现已经支持了:
https://www.reddit.com/r/cpp/comments/88mmjk/visualcpptoolscommunitydaily_can_support/
微软官方博客:
https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus/
而 GCC 在 8.0 也将支持 std::filesystem https://www.reddit.com/r/cpp/comments/7o9kg6/gcc_80_support_stdfilesystem_include_filesystem/
现在没有进一步消息的只剩 libcxx 了。
这意味着可以这样写文件系统相关的代码了:
#include <iostream>
#include <fstream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
fs::create_directories("sandbox/dir/subdir");
std::ofstream("sandbox/file1.txt").put('a');
fs::copy("sandbox/file1.txt", "sandbox/file2.txt");
fs::copy("sandbox/dir", "sandbox/dir2");
fs::copy("sandbox", "sandbox/copy", fs::copy_options::recursive);
fs::remove_all("sandbox");
return 0;
}