问题标签 [std-filesystem]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
16684 浏览

c++ - 使用链接错误C++17 中的成员

我在 Ubuntu 16.04 上使用 gcc 7.2,我需要使用 C++17 中的新文件系统库。即使确实有一个名为experimental/filesystem 的库,我也不能使用它的任何成员。例如,当我尝试编译此文件时:

我收到一个编译错误,如下所示:

我究竟做错了什么?我认为代码没有任何问题,因为我只是从网站上复制粘贴的。我是否使用了错误版本的 gcc?另外,为什么我需要<experimental/filesystem>而不是只<filesystem>在 C++17 中?提前致谢。

0 投票
1 回答
169 浏览

c++ - std::experimental::directory_iterator 的意外别名

std::filesystem在 gcc 6.3.1 中使用了实验性的实现,并且遇到了一些关于std::experimental::filesystem::directory_iteratorand的非常意外的行为std::distance。具体来说,在调用 之后std::distance,原始迭代器似乎已被修改。

经过一堆无果的调试试图在我的代码中找到逻辑错误,我开始在实现中挖掘directory_iterator,最后发现迭代器在std::shared_ptr内部使用,有一个默认的复制构造函数,我假设operator++必须直接递增托管指针。

以下代码重现了该问题:

由于这种实现在传递给期望具有传统值语义的迭代器(据我所知的所有 STL 算法)的函数时会产生非常违反直觉的结果,我很难相信这是预期的行为,但是我犹豫要不要打电话给错误。

显然,这个 API 在发布时是实验性的,但我认为它旨在成为文件系统 TS 的忠实实现。我无法获得完全C++17支持的编译器,所以我一直希望在此期间使用它。

这是预期的行为,我应该期望directory_iterator在未来的版本中以这种方式工作吗?暂时我想我可以使用boost::filesystem.

谢谢!

0 投票
1 回答
1709 浏览

c++ - 如何使用 cmake 确保 C++14 编译器与实验文件系统 TS 库链接?

我正在(切换到)<std::experimental::filesystem>在我的 C++14 代码中使用,我需要能够在 Linux 上使用 GCC 5.x(以及任何支持 C++14 的编译器,或者至少是相关版本)来构建它铿锵,msvc,也许还有icc)。

现在,当我链接时,我收到有关丢失所有文件系统相关符号的错误,例如:

现在,如果我“手动”添加对libstdc++fs

那么一切都很好 - 但我如何将其推广到任何支持 C++14 的编译器?

注意:我的相关部分CMakeLists.txt如下所示:


*(当我使用boost::filesystem它时,它反而更容易了——我只需要使用FindBoost.cmake产生的任何东西。)
**-Wall我猜,使用对于其他编译器来说也是一个问题。

0 投票
2 回答
49147 浏览

visual-studio-2017 - VS2017:E0135 命名空间“std”没有成员“文件系统”

为了使用:std::filesystem从C++17库,我的项目从vs2015迁移到vs2017。

我的项目编译并运行没有错误,包含的库没有错误,但是在尝试使用时std::filesystem我得到以下信息:

1

似乎图书馆没有被包括在内,但看不出为什么不包括在内?

编辑:

0 投票
1 回答
1756 浏览

c++ - 将 std::filesystem 头文件添加到我的程序时出现编译错误

我正在尝试编译一个包含 std::filesytem 头文件的简单 C++ 程序!

编译时出现以下错误

我在使用 MingW 8.1.0 和 Clion 作为 IDE 的 Windows 操作系统上,正如https://en.cppreference.com/w/cpp/compiler_support上所描述的,似乎 GCC 8.1 已经支持 std:fileystem

工具链配置

编辑:语言级别在我的 CMakeList 中设置,如下所示

0 投票
1 回答
457 浏览

uwp - std::filesystem::directory_iterator in C++/CX UWP app can't find directory?

I'm writing a cross-platform app, so thought I'd do the UI in XAML with C++/CX resp. Cocoa, and the core in standard C++. However, I'm having problems accessing documents.

I present a FolderPicker and take the path and stick it in a directory_iterator, but the directory iterator doesn't find any files, and if I call exists() on the path, it says false.

I've googled high and low, but everything on the net tells me that I should just have access to the files once I have the StorageFolder, and nothing refers to Standard C++17 APIs.

What do I have to do to give the standard library access to the files?

I bring up the file picker using:

Code that takes this string (as a std::string) and tries to list files in that directory:

And my manifest:

The full code is at https://github.com/uliwitness/vanguardbot in case you want to run it and step through (just make up username/password for the UI, the failure is before that point). Relevant files are windows/MainPage.xaml.cpp (vanguardbot_win::MainPage::FolderPicker_Click), common/vanguardbot.cpp (vanguardbot::connect) and vanguardbot/windows/Package.appxmanifest. The solution is vanguardbot_win.sln at the top level.

0 投票
3 回答
5586 浏览

c++ - C++17 std::filesystem::path 中的本机路径分隔符错误?

我从升级#include <experimental/filesystem>#include <filesystem>. 似乎该std::filesystem::path::wstring方法没有返回与 in 相同的字符串experimental::filesystem。我编写了以下包含输出结果的小测试程序。

根据https://en.cppreference.com/w/cpp/filesystem/path/string

返回值

本机路径名格式的内部路径名,转换为指定的字符串类型。

该程序在 Windows 10 上运行,并使用 Visual Studio 2017 版本 15.8.0 编译。我希望本机路径名是C:\temp\foo.

问题:这是一个错误std::filesystem::path吗?

0 投票
2 回答
5317 浏览

c++ - std::filesystem::copy() 和 std::filesystem::copy_file() 有什么区别?

这段代码std::filesystem::copy()和有什么区别?std::filesystem::copy_file()

文档说:

  • copy(): "复制文件或目录"
  • copy_file(): "复制文件内容"

由于我在此示例中复制的是单个文件而不是目录,因此这两个调用是否相同?

(我使用的是 g++ 8.2.0。记得链接到 libstdc++fs 否则你会有未定义的对 std::filesystem 的引用。)

0 投票
1 回答
393 浏览

c++ - 如何在 C++17 中检索 std::filesystem::file_time_type 的时钟类型

由于在 C++17 中std::filesystem::file_time_type使用了一个微不足道的时钟,有没有办法file_time_type用 C++17** 检索实际的时钟类型?

目标是将时间转换为std::chrono::system_clock在流中使用它。


** 在 C++20 中,file_time_type将使用std::chrono::file_clock,它具有operator<<并且可以使用 . 转换为其他时钟std::chrono::clock_cast

0 投票
0 回答
5554 浏览

c++ - 即使声明支持也不能使用`std::filesystem`

最新版本的 GCC 和 clang 支持 C++17 的 std::filesystem ( ref )。

为什么这个程序不能编译?

我使用来自在线编译器的最新编译器版本对其进行了测试,具有以下编译器选项:

从 clang 我得到这些链接器错误:

如果我使用 fs::permissions 取消注释该行,我会收到以下编译时错误:

我从 GCC 得到类似的错误。

我究竟做错了什么?这些编译器是否有可能支持 C++17 语言,但不支持它的全部库?