命名空间
变体
操作

std::experimental::filesystem::path::parent_path

来自 cppreference.cn
< cpp‎ | experimental‎ | fs‎ | path
 
 
实验性
技术规范
文件系统库 (filesystem TS)
库基础 (library fundamentals TS)
库基础 2 (library fundamentals TS v2)
库基础 3 (library fundamentals TS v3)
并行性扩展 (parallelism TS)
并行性扩展 2 (parallelism TS v2)
并发扩展 (concurrency TS)
并发扩展 2 (concurrency TS v2)
概念 (concepts TS)
范围 (ranges TS)
反射 (reflection TS)
数学特殊函数 (special functions TR)
实验性非TS
模式匹配
线性代数
std::execution
契约
2D 图形
 
 
 
path parent_path() const;
(filesystem TS)

返回父目录的路径。如果 empty() 或路径中只有一个元素 ( begin() == --end() ),则返回空路径。

结果路径通过将范围 [begin()--end()) 中的所有元素附加到空路径来构造。

目录

[edit] 参数

(无)

[edit] 返回值

父目录的路径。

[edit] 异常

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

[edit] 示例

#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
 
int main()
{
    for (fs::path p : {"/var/tmp/example.txt", "/", "/var/tmp/."})
        std::cout << "The parent path of " << p
                  << " is " << p.parent_path() << '\n';
}

可能的输出

The parent path of "/var/tmp/example.txt" is "/var/tmp"
The parent path of "/" is ""
The parent path of "/var/tmp/." is "/var/tmp"

[edit] 参见