在线文档教程
C++
文件系统 | Filesystem

std::filesystem::path::root_directory

文件系统::path::root[医]目录

path root_directory() const;(since C++17)

返回路径的根目录。如果路径不包括根名称,则返回path()...

参数

%280%29

返回值

路径的根目录。

例外

%280%29

二次

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

二次

另见

root_namereturns the root-name of the path, if present (public member function)
root_pathreturns the root path of the path, if present (public member function)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/filesystem/path/root[医]目录