std::filesystem::directory_entry::path
来自cppreference.com
< cpp | filesystem | directory
entry
文件系统库
类 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
函数 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
文件类型 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::filesystem::directory_entry
成员函数 | ||||
修改器 | ||||
观察器 | ||||
directory_entry::pathdirectory_entry::operator
const
path&
|
||||
(C++20
前)(C++20
前)(C++20
前)(C++20
前)(C++20
前)(C++20)
|
||||
非成员函数 | ||||
const
std::filesystem::path&
path()
const
noexcept;
|
(C++17 起) | |
operator
const
std::filesystem::path&
()
const
noexcept;
|
(C++17 起) | |
返回 directory_entry 所保有的路径对象。
参数
(无)
返回值
directory_entry 所保有的 path 对象。
示例
运行此代码
#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)) { // 显式转换 std::cout << get_stem(file.path()) << '\n'; // 隐式转换 std::cout << get_stem(file) << '\n'; } fs::remove_all(dir); }
可能的输出:
two two one one three three
参阅
本节未完成 |