• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <filesystem>

    std::filesystem::directory_entry::path

    const path& path() const noexcept;
    

    概要

    パスを取得する。

    戻り値

    保持しているpathオブジェクトへの参照を返す。

    例外

    投げない

    #include <iostream>
    #include <filesystem>
    #include <fstream>
    
    namespace fs = std::filesystem;
    
    int main()
    {
      fs::create_directory("dir");
      fs::create_directory("dir/inner_dir");
      std::ofstream{"dir/a.txt"};
    
      // dirディレクトリ内のファイルを列挙する
      for (const fs::directory_entry& x : fs::directory_iterator("dir")) {
        std::cout << x.path() << std::endl;
      }
    }
    

    出力例

    "dir/inner_dir"
    "dir/a.txt"
    

    バージョン

    言語

    • C++17

    処理系