std::filesystem::directory_entry::path
来自cppreference.com
< cpp | filesystem | directory entry
conststd::filesystem::path& path()constnoexcept; | (C++17 起) | |
operator conststd::filesystem::path&()constnoexcept; | (C++17 起) | |
返回 directory_entry
所指代的全路径。
目录 |
[编辑]参数
(无)
[编辑]返回值
directory_entry
所指代的全路径。
[编辑]示例
运行此代码
#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)){// 显式转换std::cout<< get_stem(file.path())<<'\n'; // 隐式转换std::cout<< get_stem(file)<<'\n';} fs::remove_all(dir);}
可能的输出:
two two one one three three
[编辑]参阅
(C++17) | 表示路径 (类) |