命名空间
变体
操作

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

来自 cppreference.cn
< cpp‎ | filesystem‎ | path
 
 
 
 
iterator begin() const;
(1) (自 C++17 起)
iterator end() const;
(2) (自 C++17 起)
1) 返回指向路径首元素的迭代器。如果路径为空,则返回的迭代器等于 end()
2) 返回指向路径末尾后一个位置的迭代器。解引用此迭代器是未定义行为。

此迭代器对表示的序列包含以下内容

  1. 根名 (如果存在)。
  2. 根目录 (如果存在)。
  3. 文件名 序列,省略任何目录分隔符。
  4. 如果路径中最后一个 文件名 后有目录分隔符,则结束迭代器之前的最后一个元素是一个空元素。

内容

[编辑] 参数

(无)

[编辑] 返回值

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" │