std::filesystem::directory_entry::path
From cppreference.com
< cpp | filesystem | directory entry
| const std::filesystem::path& path() const noexcept; |
(C++17以降) | |
| operator const std::filesystem::path& () const noexcept; |
(C++17以降) | |
ディレクトリ エントリが参照するフルパスを返します。
目次 |
[編集] パラメータ
(なし)
[編集] 戻り値
ディレクトリ エントリが参照するフルパス。
[編集] 例
このコードを実行
#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 (const auto& file : fs::directory_iterator(dir)) { // Explicit conversion std::cout << get_stem(file.path()) << '\n'; // Implicit conversion std::cout << get_stem(file) << '\n'; } fs::remove_all(dir); }
実行結果の例
two two one one three three
[編集] 関連項目
| (C++17) |
パスを表現する (クラス) |