Visual Studio 2017 15.7 Preview 3 已经支持 std::filesystem 了

2018-04-10 21:44:48 +08:00
 forcecharlie

半个多月前,就有消息说 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;
}

2421 次点击
所在节点    C
7 条回复
zhiqiang
2018-04-11 07:48:58 +08:00
boost 早就有了,你们都不用 boost 的吗?
zhiqiang
2018-04-11 07:49:38 +08:00
对大多数人和项目而言,升级编译器比使用 boost 难多了。
forcecharlie
2018-04-11 09:37:09 +08:00
@zhiqiang std::filesystem 就是基于 boost 的,说实话并不想用 boost,而 asio 都是用的独立版。
nyanyh
2018-04-11 09:53:07 +08:00
现在 C++什么都有了吗🌚感觉越发展越臃肿了
P0P
2018-04-11 10:01:00 +08:00
可以考虑 qt
timsensor
2018-04-11 13:08:35 +08:00
很多年前就有了,不过是放在另一个命名空间
我还是选择用 QT
zhiqiang
2018-04-21 16:30:30 +08:00
@forcecharlie 为什么不用 boost ?我听说二进制会变大,不知道会变大多少

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/445773

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX