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

履歴 編集

function
<filesystem>

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

path root_path() const;

概要

パスが保持しているルートパスを取得する。

ルートパスは、ルート名とディレクトリ区切り文字を合わせた文字列である。

戻り値

POSIXベースシステムでの例

#include <iostream>
#include <filesystem>

namespace fs = std::filesystem;

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

  std::cout << root_p << std::endl;
}

出力

"/"

Windowsでの例

#include <iostream>
#include <filesystem>

namespace fs = std::filesystem;

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

  std::cout << root_p << std::endl;
}

出力

"C:/"

バージョン

言語

  • C++17

処理系