最終更新日時(UTC):
が更新

履歴 編集

function
<filesystem>

std::filesystem::path::has_root_name(C++17)

bool has_root_name() const;

概要

パスにルート名が含まれているか判定する。

戻り値

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;
  }
}

出力

""
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;
  }
}

出力

"C:"
has root name

バージョン

言語

  • C++17

処理系