Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::filesystem::directory_entry::path

      From cppreference.com
      <cpp‎ |filesystem‎ |directory entry
       
       
      Filesystem library
      Classes
      Functions
      File types
       
      std::filesystem::directory_entry
      Member functions
      Modifiers
      Observers
      directory_entry::pathdirectory_entry::operator const path&
      Non-member functions
       
      conststd::filesystem::path& path()constnoexcept;
      (since C++17)
      operatorconststd::filesystem::path&()constnoexcept;
      (since C++17)

      Returns the full path the directory entry refers to.

      Contents

      [edit]Parameters

      (none)

      [edit]Return value

      The full path the directory entry refers to.

      [edit]Example

      Run this code
      #include <filesystem>#include <fstream>#include <iostream> namespace fs= std::filesystem; std::string get_stem(const fs::path& p){return p.stem().string();}void create_file(const fs::path& p){std::ofstream o{p};} int main(){const fs::path dir{"tmp_dir"};    fs::create_directory(dir);    create_file(dir/"one");    create_file(dir/"two");    create_file(dir/"three"); for(constauto& file: fs::directory_iterator(dir)){// Explicit conversionstd::cout<< get_stem(file.path())<<'\n'; // Implicit conversionstd::cout<< get_stem(file)<<'\n';}     fs::remove_all(dir);}

      Possible output:

      twotwooneonethreethree

      [edit]See also

      (C++17)
      represents a path
      (class)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/filesystem/directory_entry/path&oldid=159789"

      [8]ページ先頭

      ©2009-2025 Movatter.jp