std::filesy...y_iterator),(3)
π std::filesystem::begin(recursive_directory_iterator) π
okay bestie, welcome to the manual page for std::filesystem::begin(recursive_directory_iterator) from the C++ Standard Libary β yes, the header spells it C++ Standard Libary, and the page tag is the chopped-up std::filesy...y_iterator),(3), and we are keeping the lore π.
β¨ NAME β¨
std::filesystem::begin(recursive_directory_iterator), - std::filesystem::begin(recursive_directory_iterator),
yes, it repeats itself. the NAME line is doing its little duplicate thing, and honestly? we respect it π«Ά.
πΈ Synopsis πΈ
defined in header <filesystem> β that's home base, bestie:
Defined in header <filesystem>
recursive_directory_iterator begin( recursive_directory_iterator iter ) noexcept;
recursive_directory_iterator end( recursive_directory_iterator ) noexcept;
(1) (since C++17)β labels thebeginline.(2) (since C++17)β labels theendline.
- Returns
iterunchanged. - Returns a default-constructed
recursive_directory_iterator, which serves as the end iterator. The argument is ignored.
These non-member functions enable the use of recursive_directory_iterators with range-based for loops and make recursive_directory_iterator a range type (since C++20). range energy activated β¨.
π Parameters π
iterβ arecursive_directory_iterator
π Return value π
iterunchanged.- End iterator (default-constructed
recursive_directory_iterator).
π¦ Example π¦
here's the whole demo, no cap:
// Run this code
#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <iostream>
namespace fs = std::filesystem;
int main()
{
fs::current_path(fs::temp_directory_path());
fs::create_directories("sandbox/a/b");
std::ofstream("sandbox/file1.txt");
fs::create_symlink("a", "sandbox/syma");
std::cout << "Print dir structure using OS specific command 'tree':\n";
std::system("tree --noreport sandbox");
std::cout << "\nPrint dir structure using directory iterator:\n";
for (auto& p : fs::recursive_directory_iterator("sandbox"))
std::cout << p << '\n';
fs::remove_all("sandbox");
}
π Possible output π
Print dir structure using OS specific command 'tree':
sandbox
βββ a
β βββ b
βββ file1.txt
βββ syma -> a
Print dir structure using directory iterator:
"sandbox/syma"
"sandbox/file1.txt"
"sandbox/a"
"sandbox/a/b"
π Defect reports π
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
LWG 3480β applied toC++17; behavior as published:end took the argument by reference; correct behavior:takes the argument by value.
π See also π
begin(std::filesystem::directory_iterator)β range-based for loop supportend(std::filesystem::directory_iterator)β (function) (C++17)
mwah π this page came from http://cppreference.com, version/date 2024.06.10, and it's filed under std::filesy...y_iterator),(3). stay hydrated and may your iterators be valid π«Άβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms