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

std::filesystem::path::lexically_relative

path lexically_normal() const;

(1)

(since C++17)

path lexically_relative(const path& base) const;

(2)

(since C++17)

path lexically_proximate(const path& base) const;

(3)

(since C++17)

1%29*this转换成范式%28无冗余网点点点元素,如果最后一个元素是非根目录分隔符,网点加%29

2%29*this相对于base的第一个不匹配元素。*thisbase好像auto [a, b] = mismatch(begin(), end(), base.begin(), base.end()),然后

  • 如果a == begin()b == base.begin()、回报path()%28空路径%29。
  • 否则,如果a == end()b == base.end()、回报path(".")
  • 否则,返回由默认构造的对象组成的对象。path()然后是一份申请operator/=(path(".."))对于半开放范围内的每个元素[b, base.end()),然后通过一个应用程序operator/=对于半开放范围内的每个元素[a, end())...

3%29如果lexically_relative(base)不是一条空的路,把它还给我。否则返回*this...

参数

%280%29

返回值

1%29路径的正常形式

2%29路径的相对形式

3%29这条路的最接近的形式

例外

%280%29

注记

这些转换都是纯粹的词汇。它们不检查路径是否存在,不遵循符号链接,也根本不访问文件系统。的符号跟随对应方lexically_relativelexically_proximate,见relativeproximate...

在Windows上,返回的路径有反斜杠%28首选分隔符%29,

二次

代码语言:javascript
复制
#include <iostream>
#include <filesystem>
#include <cassert>
namespace fs = std::filesystem;
 
int main()
{
    assert(fs::path("foo/./bar/..").lexically_normal() == "foo");
    assert(fs::path("foo/.///bar/../").lexically_normal() == "foo/.");
 
    assert(path("/a/d").lexically_relative("/a/b/c") == "../../d");
    assert(path("/a/b/c").lexically_relative("/a/d") == "../b/c");
    assert(path("a/b/c").lexically_relative("a") == "b/c");
    assert(path("a/b/c").lexically_relative("a/b/c/x/y") == "../..");
    assert(path("a/b/c").lexically_relative("a/b/c") == ".");
    assert(path("a/b").lexically_relative("c/d") == "");
}

二次

另见

relativeproximate (C++17)

composes a relative path (function)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com