std::filesystem::path::relative_path

path relative_path() const;
(C++17 起)

返回相对于 root-path 的路径,即由 *thisroot-path 后的每个通用格式路径组分组成的路径名。若 *this 是空路径,则返回空路径。

目录

参数

(无)

返回值

相对于 root_path 的路径。

异常

(无)

示例

#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
 
int main()
{
    fs::path p = fs::current_path();
 
    std::cout << "The current path " << p << " decomposes into:\n"
              << "root-path " << p.root_path() << '\n'
              << "relative path " << p.relative_path() << '\n';
}

可能的输出:

The current path "C:\Users\abcdef\Local Settings\temp" decomposes into:
root-path "C:\"
relative path "Users\abcdef\Local Settings\temp"

参阅

若存在则返回路径的根名
(公开成员函数)
若存在则返回路径的根目录
(公开成员函数)
若存在则返回路径的根路径
(公开成员函数)

版本历史

  • (当前 | 先前) 2017年5月1日 (一) 05:33Fruderica讨论 | 贡献. . (1,177字节) (+1,177). . (以“{{cpp/filesystem/path/title|relative_path}} {{cpp/filesystem/path/navbar}} {{dcl begin}} {{dcl | since=c++17 | 1= path relative_path() const; }} {{dcl end}} 返回...”为内容创建页面)