std::experimental::filesystem::path:: relative_path
From cppreference.net
<
cpp
|
experimental
|
fs
|
path
C++
Experimental
| Technical Specification | ||||
| Filesystem library (filesystem TS) | ||||
| Library fundamentals (library fundamentals TS) | ||||
| Library fundamentals 2 (library fundamentals TS v2) | ||||
| Library fundamentals 3 (library fundamentals TS v3) | ||||
| Extensions for parallelism (parallelism TS) | ||||
| Extensions for parallelism 2 (parallelism TS v2) | ||||
| Extensions for concurrency (concurrency TS) | ||||
| Extensions for concurrency 2 (concurrency TS v2) | ||||
| Concepts (concepts TS) | ||||
| Ranges (ranges TS) | ||||
| Reflection (reflection TS) | ||||
| Mathematical special functions (special functions TR) | ||||
| Experimental Non-TS | ||||
| Pattern Matching | ||||
| Linear Algebra | ||||
| std::execution | ||||
| Contracts | ||||
| 2D Graphics |
Filesystem library
| Classes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| File types | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
path
| Member functions | ||||
| Path decomposition | ||||
| Non-member functions | ||||
|
path relative_path
(
)
const
;
|
(文件系统 TS) | |
返回相对于 根路径 的路径。若 * this 为空路径,则返回空路径。
目录 |
参数
(无)
返回值
相对于 根路径 的路径。
异常
可能抛出实现定义的异常。
示例
运行此代码
#include <experimental/filesystem> #include <iostream> namespace fs = std::experimental::filesystem; int main() { fs::path p = fs::current_path(); std::cout << "当前路径 " << p << " 可分解为:\n" << "根路径 " << p.root_path() << '\n' << "相对路径 " << p.relative_path() << '\n'; }
可能的输出:
当前路径 "C:\Users\abcdef\Local Settings\temp" 可分解为: 根路径 "C:\" 相对路径 "Users\abcdef\Local Settings\temp"
参见
|
返回路径的根名称(如果存在)
(公开成员函数) |
|
|
返回路径的根目录(如果存在)
(公开成员函数) |
|
|
返回路径的根路径(如果存在)
(公开成员函数) |