命名空间
变体
操作

std::filesystem::path::relative_path

来自 cppreference.cn
< cpp‎ | filesystem‎ | path
 
 
 
 
path relative_path() const;
(C++17 起)

返回相对于 根路径 (root-path) 的路径,即由 *this 的通用格式组件中位于 根路径 (root-path) 之后的部分组成的路径名。如果 *this 是空路径,则返回空路径。

目录

[编辑] 参数

(无)

[编辑] 返回值

相对于根路径的路径。

[编辑] 异常

可能抛出实现定义的异常。

[编辑] 示例

#include <filesystem>
#include <iostream>
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"

[编辑] 参阅

返回路径的根名(如果存在)
(public member function) [编辑]
返回路径的根目录(如果存在)
(public member function) [编辑]
返回路径的根路径(如果存在)
(public member function) [编辑]