Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

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

      From cppreference.com
      <cpp‎ |filesystem‎ |path
       
       
      Filesystem library
      Classes
      Functions
      File types
       
      std::filesystem::path
      Member types
      Member constants
      Member functions
      Path decomposition
      Non-member functions
      (until C++20)(until C++20)(until C++20)(until C++20)(until C++20)(C++20)
      Helper classes
       
      iterator begin()const;
      (1)(since C++17)
      iterator end()const;
      (2)(since C++17)
      1) Returns an iterator to the first element of the path. If the path is empty, the returned iterator is equal toend().
      2) Returns an iterator one past the last element of the path. Dereferencing this iterator is undefined behavior.

      The sequence denoted by this pair of iterators consists of the following:

      1. root-name (if any).
      2. root-directory (if any).
      3. Sequence offile-names, omitting any directory separators.
      4. If there is a directory separator after the lastfile-name in the path, the last element before the end iterator is an empty element.

      Contents

      [edit]Parameters

      (none)

      [edit]Return value

      1) Iterator to the first element of the path.
      2) Iterator one past the end of the path

      [edit]Exceptions

      May throw implementation-defined exceptions.

      [edit]Example

      Run this code
      #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";#   endifstd::cout<<"Examining the path "<< p<<" through iterators gives\n";for(auto it= p.begin(); it!= p.end();++it)std::cout<<*it<<" │ ";std::cout<<'\n';}

      Possible output:

      --- 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" │
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/filesystem/path/begin&oldid=158015"

      [8]ページ先頭

      ©2009-2025 Movatter.jp