- filesystem[meta header]
- std::filesystem[meta namespace]
- path[meta class]
- function[meta id-type]
- cpp17[meta cpp]
bool has_root_name() const;
パスにルート名が含まれているか判定する。
return !root_name().empty();
- root_name()[link root_name.md]
- empty()[link empty.md]
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
fs::path p = "/usr/bin/clang";
fs::path root_name = p.root_name();
std::cout << root_name << std::endl;
if (p.has_root_name()) {
std::cout << "has root name" << std::endl;
}
else {
std::cout << "doesn't have root name" << std::endl;
}
}
- has_root_name()[color ff0000]
- p.root_name()[link root_name.md]
""
doesn't have root name
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
fs::path p = "C:/Program Files/a.txt";
fs::path root_name = p.root_name();
std::cout << root_name << std::endl;
if (p.has_root_name()) {
std::cout << "has root name" << std::endl;
}
else {
std::cout << "doesn't have root name" << std::endl;
}
}
- has_root_name()[color ff0000]
- p.root_name()[link root_name.md]
"C:"
has root name
- C++17
- Clang:
- GCC: 8.1 [mark verified]
- Visual C++: 2017 Update 7 [mark verified]