gpt4 book ai didi

c++ - 为什么 std::experimental::filesystem::path 不接受像 "*"这样的通配符?

转载 作者:行者123 更新时间:2023-11-27 23:57:17 24 4
gpt4 key购买 nike

#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 编译正常,但运行时错误提示:

terminate called after throwing an instance of 'std::experimental::filesystem::v1::__cxx11::filesystem_error'
what(): filesystem error: cannot canonicalize: No such file or directory [/usr/include/c++/../sys/*] [/data/svn/yaoxinliu] Aborted

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

最佳答案

根据 documentation

std::experimental::filesystem::canonical converts path p to a canonical absolute path, i.e. an absolute path that has no dot, dot-dot elements or symbolic links.

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

关于c++ - 为什么 std::experimental::filesystem::path 不接受像 "*"这样的通配符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41669857/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com