std::filesystem::directory_entry:: path
From de.cppreference.net
<
cpp
|
filesystem
|
directory entry
|
const
std::
filesystem
::
path
&
path
(
)
const
noexcept
;
|
(seit C++17) | |
|
operator
const
std::
filesystem
::
path
&
(
)
const
noexcept
;
|
(seit C++17) | |
Gibt den vollständigen Pfad zurück, auf den der Verzeichniseintrag verweist.
Inhaltsverzeichnis |
Parameter
(keine)
Rückgabewert
Der vollständige Pfad, auf den der Verzeichniseintrag verweist.
Beispiel
Diesen Code ausführen
#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)) { // Explizite Konvertierung std::cout << get_stem(file.path()) << '\n'; // Implizite Konvertierung std::cout << get_stem(file) << '\n'; } fs::remove_all(dir); }
Mögliche Ausgabe:
two two one one three three
Siehe auch
|
(C++17)
|
repräsentiert einen Pfad
(Klasse) |