std::filesystem::path::begin, std::filesystem::path::end
来自cppreference.com
<tbody>
</tbody>
iterator begin() const; |
(1) | (C++17 起) |
iterator end() const; |
(2) | (C++17 起) |
1) 返回指向路径首元素的迭代器。若路径为空,则返回的迭代器等于 end()。
2) 返回路径最后元素后一位的迭代器。解引用此迭代器是未定义行为。
这对迭代器所指代的序列由下列内容组成:
- 根名(若存在)
- 根目录(若存在)
- 文件名 的序列,忽略任何目录分隔符
- 若在路径最后的 文件名 后有目录分隔符,则尾迭代器前的最后元素是空元素。
参数
(无)
返回值
1) 指向路径首元素的迭代器。
2) 路径结束后一位的迭代器。
异常
可能会抛出由实现定义的异常。
示例
运行此代码
#include <filesystem>
#include <iostream>
namespace fs = std::filesystem;
int main()
{
const fs::path p =
# ifdef _WIN32
"C:\\users\\abcdef\\AppData\\Local\\Temp\\";
# else
"/home/user/.config/Cppcheck/Cppcheck-GUI.conf";
# endif
std::cout << "Examining the path " << p << " through iterators gives\n";
for (auto it = p.begin(); it != p.end(); ++it)
std::cout << *it << " │ ";
std::cout << '\n';
}
可能的输出:
--- Windows ---
Examining the path "C:\users\abcdef\AppData\Local\Temp\" through iterators gives
"C:" │ "/" │ "users" │ "abcdef" │ "AppData" │ "Local" │ "Temp" │ "" │
--- UNIX ---
Examining the path "/home/user/.config/Cppcheck/Cppcheck-GUI.conf" through iterators gives
"/" │ "home" │ "user" │ ".config" │ "Cppcheck" │ "Cppcheck-GUI.conf" │