• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <filesystem>

    std::filesystem::path::root_directory

    path root_directory() const;
    

    概要

    パスが保持しているルートディレクトリを取得する。

    ルートディレクトリは、ルート名に続いて現れる実装定義のディレクトリ区切り文字である。

    戻り値

    汎用フォーマットのパスがルートディレクトリを保持している場合、それを返す。そうでなければ空のパスを返す。

    POSIXベースシステムでの例

    #include <iostream>
    #include <filesystem>
    
    namespace fs = std::filesystem;
    
    int main()
    {
      fs::path p = "/usr/bin/clang";
      fs::path root_dir = p.root_directory();
    
      std::cout << root_dir << std::endl;
    }
    

    出力

    "/"
    

    Windowsでの例

    #include <iostream>
    #include <filesystem>
    
    namespace fs = std::filesystem;
    
    int main()
    {
      fs::path p = "C:/Program Files/a.txt";
      fs::path root_dir = p.root_directory();
    
      std::cout << root_dir << std::endl;
    }
    

    出力

    "/"
    

    バージョン

    言語

    • C++17

    処理系