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

履歴 編集

function
<filesystem>

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

bool has_root_path() const;

概要

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

戻り値

POSIXベースシステムでの例

#include <iostream>
#include <filesystem>

namespace fs = std::filesystem;

int main()
{
  fs::path p = "/usr/bin/clang";

  fs::path root_path = p.root_path();
  std::cout << root_path << std::endl;

  if (p.has_root_path()) {
    std::cout << "has root path" << std::endl;
  }
  else {
    std::cout << "doesn't have root path" << std::endl;
  }
}

出力

"/"
has root path

Windowsでの例

#include <iostream>
#include <filesystem>

namespace fs = std::filesystem;

int main()
{
  fs::path p = "C:/Program Files/a.txt";

  fs::path root_path = p.root_path();
  std::cout << root_path << std::endl;

  if (p.has_root_path()) {
    std::cout << "has root path" << std::endl;
  }
  else {
    std::cout << "doesn't have root path" << std::endl;
  }
}

出力

"C:/"
has root path

バージョン

言語

  • C++17

処理系