名前空間
変種
操作

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

From cppreference.com
< cpp‎ | filesystem‎ | path
 
 
 
 
iterator begin() const;
(1) (C++17以降)
iterator end() const;
(2) (C++17以降)
1) パス の最初の要素へのイテレータを返します。パスが空の場合、返されるイテレータは end() と等しくなります。
2) パス の最後の要素の次を指すイテレータを返します。このイテレータを逆参照することは未定義の動作です。

このイテレータのペアが示すシーケンスは、以下の要素で構成されます。

  1. ルート名 (存在する場合)。
  2. ルートディレクトリ (存在する場合)。
  3. ディレクトリセパレータを省略した ファイル名 のシーケンス。
  4. パスの最後の ファイル名 の後にディレクトリセパレータがある場合、end イテレータの前の最後の要素は空の要素になります。

目次

[編集] パラメータ

(なし)

[編集] 戻り値

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" │
English 日本語 中文(简体) 中文(繁體)