##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

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

From cppreference.com
< cpp‎ | experimental‎ | fs‎ | directory iterator

directory_iterator begin( directory_iterator iter ); | (1) | (filesystem TS)
directory_iterator end( const directory_iterator& ); | (2) | (filesystem TS)

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_iterator`s with range-based for loops.

### [edit] Parameters

iter | - | a directory_iterator

### [edit] Return value

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

### [edit] Exceptions

`noexcept` specification:
noexcept

### [edit] Example

Run this code

    #include <fstream>
    #include <iostream>
    #include <experimental/filesystem>
    namespace fs = std::experimental::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"

### [edit] See also

filesystem::begin(filesystem::recursive_directory_iterator)filesystem::end(filesystem::recursive_directory_iterator) | range-based for loop support (function) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/experimental/fs/directory_iterator/begin&oldid=91332"
Category:

- unconditionally noexcept

Hidden categories:

- Pages with unreviewed unconditional noexcept template
- Pages with unreviewed noexcept template