std::filesystem::directory_entry:: path
From es.cppreference.net
<
cpp
|
filesystem
|
directory entry
|
const
std::
filesystem
::
path
&
path
(
)
const
noexcept
;
|
(desde C++17) | |
|
operator
const
std::
filesystem
::
path
&
(
)
const
noexcept
;
|
(desde C++17) | |
Devuelve la ruta completa a la que se refiere la entrada del directorio.
Contenidos |
Parámetros
(ninguno)
Valor de retorno
La ruta completa a la que se refiere la entrada del directorio.
Ejemplo
Ejecutar este código
#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)) { // Conversión explícita std::cout << get_stem(file.path()) << '\n'; // Conversión implícita std::cout << get_stem(file) << '\n'; } fs::remove_all(dir); }
Salida posible:
two two one one three three
Véase también
|
(C++17)
|
representa una ruta
(clase) |