Skip to content

Files

97 lines (75 loc) · 1.59 KB

has_root_name.md

File metadata and controls

97 lines (75 loc) · 1.59 KB

has_root_name

  • 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]

POSIXベースシステムでの例

#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

Windowsでの例

#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

処理系