std::filesystem::path::begin, std::filesystem::path::end

iterator begin() const;
(1) (C++17 起)
iterator end() const;
(2) (C++17 起)
1) 返回指向路径首元素的迭代器。若路径位空,则返回的迭代器等于 end()
2) 返回路径最后元素后一位的迭代器。解引用此迭代器是未定义行为。

这对迭代器所指代的序列由下列内容组成:

1) root-name (若存在)
2) root-directory (若存在)
3) file-name 的序列,忽略任何目录分隔符
4) 若在路径最后的 file-name 之后有目录分隔符,则尾迭代器前的最后元素是虚设的 dot 文件名。

目录

参数

(无)

返回值

1) 指向路径首元素的迭代器。
2) 路径结束后一位的迭代器。

异常

(无)

示例

#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
    fs::path p = "C:\\users\\abcdef\\AppData\\Local\\Temp\\";
    std::cout << "Examining the path " << p << " through iterators gives\n";
    for(auto& e : p)
        std::cout << e << '\n';
}

输出:

Examining the path "C:\users\abcdef\AppData\Local\Temp\" through iterators gives
"C:"
"/"
"users"
"abcdef"
"AppData"
"Local"
"Temp"
"."

版本历史

  • (当前 | 先前) 2017年5月1日 (一) 04:17Fruderica讨论 | 贡献. . (1,392字节) (+1,392). . (以“{{cpp/filesystem/path/title|begin|end}} {{cpp/filesystem/path/navbar}} {{dcl begin}} {{dcl | num=1 | since=c++17 | 1= iterator begin() const; }} {{dcl | num=2 | sinc...”为内容创建页面)