为什么 std::experimental::filesystem::p ath 不接受像 "*" 这样的通配符?

Why does std::experimental::filesystem::path not accept wildcards like "*"?

本文关键字:通配符 不接受 experimental std filesystem 为什么 ath      更新时间:2023-10-16
#include <string>
#include <iostream>
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
int main()
{
    fs::path p("/usr/include/c++/../sys/*");
    p = fs::canonical(p);
}

gcc 6.2.0 编译正常,但运行时错误显示:

在抛出 的实例后终止调用 'std::experimental::filesystem::v1::__cxx11::filesystem_error"
what():文件系统错误:无法规范化:没有这样的文件或 目录 [/usr/include/c++/../sys/*] [/data/svn/yaoxinliu] 已中止

为什么std::experimental::filesystem::path不接受像*这样的通配符

根据文档

std::experimental::filesystem::canonical将路径 p 转换为规范的绝对路径,即没有点、点-点元素或符号链接的绝对路径。

由于std::experimental::filesystem::canonical还必须取消引用路径中包含的符号链接,因此它只能接受现有文件或目录的路径。