Namespaces
Variants

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

From cppreference.net
path parent_path ( ) const ;
(文件系统 TS)

返回父目录的路径。若路径为空或仅包含单个元素( begin ( ) == -- end ( ) )则返回空路径。

生成的路径是通过将区间 [ begin ( ) , -- end ( ) ) 内的所有元素追加到空路径而构建的。

目录

参数

(无)

返回值

指向父目录的路径。

异常

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

示例

#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"

参见