CppDS.com

C++ 98 11 14 17 20 手册

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

来自cppreference.com
< cpp‎ | filesystem‎ | path
 
 
 
 
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 后有目录分隔符,则尾迭代器前的最后元素是空元素。

参数

(无)

返回值

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"
""
关闭