首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::filesystem::weakly_canonical

Defined in header <filesystem>

?

?

path canonical( const std::filesystem::path& p, const std::filesystem::path& base = std::filesystem::current_path() );

(1)

(since C++17)

path canonical( const std::filesystem::path& p, std::error_code& ec );

(2)

(since C++17)

path canonical( const std::filesystem::path& p, const std::filesystem::path& base, std::error_code& ec );

(3)

(since C++17)

path weakly_canonical(const std::filesystem::path& p);

(4)

(since C++17)

path weakly_canonical(const std::filesystem::path& p, std::error_code& ec);

(5)

(since C++17)

1-3%29转换路径p对于典型的绝对路径,即没有点、点元素或符号链接的绝对路径。如果p不是绝对路径,函数的行为就好像它首先是由absolute(p, base)absolute(p)%282%29。小径p一定存在。

4-5%29返回由operator/=从打电话的结果canonical()没有基参数,并且使用由主元素组成的路径参数。p所确定的存在%28 As的status(p)status(p, ec)%29,如果有的话,后面跟着p如果有的话是不存在的。生成的路径位于范式...

参数

p

-

a path which may be absolute or relative to base, and which must be an existing path

base

-

base path to be used in case p is relative

ec

-

error code to store error status to

返回值

1-3%29解析为同一文件的绝对路径absolute(p, base)%28或absolute(p)%282%29%29。

4-5%29形式的正常路径canonical(x)/y,其中x是由p中存在的元素的最长前导序列组成的路径,y是由p的剩余不存在元素组成的路径。

例外

不占用std::error_code&参数抛文件系统[医]误差关于基础OS API错误,使用p作为第一个论点,base作为第二个参数,操作系统错误代码作为错误代码参数。std::bad_alloc如果内存分配失败,则可能引发。过载std::error_code&参数,如果OSAPI调用失败,则将其设置为OSAPI错误代码,并执行ec.clear()如果没有错误发生。这个过载

noexcept规格:

noexcept

注记

功能canonical()是根据POSIX建模的。真实路径...

功能weakly_canonical()的操作语义。relative()...

二次

代码语言:javascript
复制
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
    fs::path p = fs::path("..") / ".." / "AppData";
    std::cout << "Current path is " << fs::current_path() << '\n'
              << "Canonical path for " << p << " is " << canonical(p) << '\n';
}

二次

可能的产出:

二次

代码语言:javascript
复制
Current path is "C:\Users\abcdef\AppData\Local\Temp"
Canonical path for "..\..\AppData" is "C:/Users\abcdef\AppData"

二次

另见

path (C++17)

represents a path (class)

absolutesystem_complete (C++17)(C++17)

composes an absolute pathconverts a path to an absolute path replicating OS-specific behavior (function)

relativeproximate (C++17)

composes a relative path (function)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com