std::filesystem::path::root_directory
来自cppreference.com
< cpp | filesystem | path
文件系统库
类 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
函数 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
文件类型 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::filesystem::path
常量 | |||||||||||||||||||||
成员函数 | |||||||||||||||||||||
|
|||||||||||||||||||||
路径分解 | |||||||||||||||||||||
非成员函数 | |||||||||||||||||||||
|
|||||||||||||||||||||
辅助类 | |||||||||||||||||||||
path root_directory() const;
|
(C++17 起) | |
返回通用格式路径的根目录。若路径(以通用格式)不包含根目录,则返回 path() 。
参数
(无)
返回值
路径的根目录。
异常
可能会抛出由实现定义的异常。
示例
运行此代码
#include <iostream> #include <filesystem> namespace fs = std::filesystem; int main() { fs::path p = fs::current_path(); std::cout << "The current path " << p << " decomposes into:\n" << "root name " << p.root_name() << '\n' << "root directory " << p.root_directory() << '\n' << "relative path " << p.relative_path() << '\n'; }
可能的输出:
The current path "C:\Users\abcdef\Local Settings\temp" decomposes into: root name "C:" root directory "\" relative path "Users\abcdef\Local Settings\temp"
参阅
若存在则返回路径的根名 (公开成员函数) |
|
若存在则返回路径的根路径 (公开成员函数) |