std::filesystem::path::root_path

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

返回路径的根路径。若路径不包含根路径,则返回 path()

等效地返回如下者: root_name() / root_directory()

目录

参数

(无)

返回值

路径的根路径。

异常

(无)

示例

#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
 
int main()
{
    std::cout << "Current root path is: " << fs::current_path().root_path() << '\n';
}

可能的输出:

Current root path is: "C:\"

参阅

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

版本历史

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