std::filesystem::begin(directory_iterator),std::filesystem::end(directory_iterator) (3) - Linux Manuals

std::filesystem::begin(directory_iterator),std::filesystem::end(directory_iterator): std::filesystem::begin(directory_iterator),std::filesystem::end(directory_iterator)

NAME

std::filesystem::begin(directory_iterator),std::filesystem::end(directory_iterator) - std::filesystem::begin(directory_iterator),std::filesystem::end(directory_iterator)

Synopsis


directory_iterator begin( directory_iterator iter ) noexcept; (1) (since C++17)
directory_iterator end( const directory_iterator& ) noexcept; (2) (since C++17)


1) Returns iter unchanged
2) Returns a default-constructed directory_iterator, which serves as the end iterator. The argument is ignored.
These non-member functions enable the use of directory_iterators with range-based for loops.

Parameters


iter - a directory_iterator

Return value


1) iter unchanged
2) End iterator (default-constructed directory_iterator)

Example


// Run this code


  #include <fstream>
  #include <iostream>
  #include <filesystem>
  namespace fs = std::filesystem;


  int main()
  {
      fs::create_directories("sandbox/a/b");
      std::ofstream("sandbox/file1.txt");
      std::ofstream("sandbox/file2.txt");
      for(auto& p: fs::directory_iterator("sandbox"))
          std::cout << p << '\n';
      fs::remove_all("sandbox");
  }

Possible output:


  "sandbox/a"
  "sandbox/file1.txt"
  "sandbox/file2.txt"

See also


                                                     range-based for loop support
begin(std::filesystem::recursive_directory_iterator) (function)
end(std::filesystem::recursive_directory_iterator)