Класс directory_iteratordirectory_iterator Class
Описывает итератор ввода, выполняющий последовательный перебор имен файлов в каталоге.Describes an input iterator that sequences through the filenames in a directory. Для итератора X
*X
результатом выражения является объект класса directory_entry
, который заключает в оболочку имя файла и все известные сведения о его состоянии.For an iterator X
, the expression *X
evaluates to an object of class directory_entry
that wraps the filename and anything known about its status.
Класс сохраняет объект типа path
, вызываемый mydir
здесь в целях демонстрации, который представляет имя каталога для упорядочения, и объект типа directory_entry
myentry
, который вызывается здесь, который представляет текущее имя файла в последовательности каталогов.The class stores an object of type path
, called mydir
here for the purposes of exposition, which represents the name of the directory to be sequenced, and an object of type directory_entry
called myentry
here, which represents the current filename in the directory sequence. Созданный по умолчанию объект типа directory_entry
имеет пустой mydir
путь и представляет итератор конца последовательности.A default constructed object of type directory_entry
has an empty mydir
pathname and represents the end-of-sequence iterator.
Например, при наличии каталога abc
с записями def
и ghi
, код:For example, given the directory abc
with entries def
and ghi
, the code:
for (directory_iterator next(path("abc")), end; next != end; ++next) visit(next->path());
будет вызывать visit
с аргументами path("abc/def")
и path("abc/ghi")
.will call visit
with the arguments path("abc/def")
and path("abc/ghi")
.
Дополнительные сведения и примеры кода см. в разделе Навигация по файловой системе (C++).For more information and code examples, see File System Navigation (C++).
СинтаксисSyntax
class directory_iterator;
КонструкторыConstructors
КонструкторConstructor | ОписаниеDescription |
---|---|
directory_iteratordirectory_iterator | Конструирует входной итератор, подающий последовательность по именам файлов в каталоге.Constructs an input iterator that sequences through the filenames in a directory. |
Функции элементовMember functions
Функция-членMember function | ОписаниеDescription |
---|---|
incrementincrement | Пытается перейти к следующему имени файла в каталоге.Attempts to advance to the next filename in the directory. |
ОператорыOperators
ОператорOperator | ОписаниеDescription |
---|---|
operator! =operator!= | Возвращает !(*this == right) .Returns !(*this == right) . |
Оператор =operator= | Операторы-члены присваивания по умолчанию работают корректно.The defaulted member assignment operators behave as expected. |
Оператор = =operator== | Возвращает, true только если оба *this и право являются итераторами конца последовательности или оба являются итераторами конца последовательности.Returns true only if both *this and right are end-of-sequence iterators or both are not end-of-sequence-iterators. |
станцииoperator* | Возвращает myentry .Returns myentry . |
Оператор->operator-> | Возвращает &**this .Returns &**this . |
operator + +operator++ | Вызывает increment() , затем возвращает *this или создает копию объекта, вызывает increment() , а затем возвращает копию.Calls increment() , then returns *this , or makes a copy of the object, calls increment() , then returns the copy. |
ТребованияRequirements
Заголовок:<experimental/filesystem>Header: <experimental/filesystem>
Пространство имен: std::experimental::filesystemNamespace: std::experimental::filesystem
directory_iterator::d irectory_iteratordirectory_iterator::directory_iterator
Первый конструктор создает итератор конца последовательности.The first constructor produces an end-of-sequence iterator. Второй и третий конструкторы хранят Pval в mydir
, а затем пытаются открыть и прочитать в mydir
виде каталога.The second and third constructors store pval in mydir
, then attempt to open and read mydir
as a directory. В случае успеха они сохраняют первое имя файла в каталоге в myentry
; в противном случае они создают итератор конца последовательности.If successful, they store the first filename in the directory in myentry
; otherwise they produce an end-of-sequence iterator.
Установленные по умолчанию конструкторы работают корректно.The defaulted construtors behave as expected.
directory_iterator() noexcept;
explicit directory_iterator(const path& pval);
directory_iterator(const path& pval, error_code& ec) noexcept;
directory_iterator(const directory_iterator&) = default;
directory_iterator(directory_iterator&&) noexcept = default;
ПараметрыParameters
Pvalpval
Путь к сохраненному имени файла.The stored file name path.
контроллерec
Код ошибки состояния.The status error code.
directory_iteratordirectory_iterator
Сохраненный объект.The stored object.
directory_iterator:: Incrementdirectory_iterator::increment
Функция пытается перейти к следующему файлу в каталоге.The function attempts to advance to the next filename in the directory. В случае успеха файл сохраняется в; в myentry
противном случае — итератор конца последовательности.If successful, it stores that filename in myentry
; otherwise it produces an end-of-sequence iterator.
directory_iterator& increment(error_code& ec) noexcept;
directory_iterator:: operator! =directory_iterator::operator!=
Оператор-член возвращает !(*this == right)
.The member operator returns !(*this == right)
.
bool operator!=(const directory_iterator& right) const;
ПараметрыParameters
Правильноright
Directory_iterator сравнивается с directory_iterator
.The directory_iterator being compared to the directory_iterator
.
directory_iterator:: operator =directory_iterator::operator=
Операторы-члены присваивания по умолчанию работают корректно.The defaulted member assignment operators behave as expected.
directory_iterator& operator=(const directory_iterator&) = default;
directory_iterator& operator=(directory_iterator&&) noexcept = default;
ПараметрыParameters
Правильноright
Directory_iterator , копируемый в directory_iterator
.The directory_iterator being copied into the directory_iterator
.
directory_iterator:: operator = =directory_iterator::operator==
Оператор-член возвращает, true
только если оба *this
и право являются итераторами конца последовательности или оба являются итераторами конца последовательности.The member operator returns true
only if both *this
and right are end-of-sequence iterators or both are not end-of-sequence-iterators.
bool operator==(const directory_iterator& right) const;
ПараметрыParameters
Правильноright
Directory_iterator сравнивается с directory_iterator
.The directory_iterator being compared to the directory_iterator
.
directory_iterator:: operator *directory_iterator::operator*
Оператор-член возвращает myentry
.The member operator returns myentry
.
const directory_entry& operator*() const;
directory_iterator:: operator — >directory_iterator::operator->
Функция-член возвращает значение &**this
.The member function returns &**this
.
const directory_entry * operator->() const;
directory_iterator:: operator + +directory_iterator::operator++
Первая функция – член вызывает increment()
, а затем возвращает *this
.The first member function calls increment()
, then returns *this
. Вторая функция-член создает копию объекта, вызывает increment()
, а затем возвращает копию.The second member function makes a copy of the object, calls increment()
, then returns the copy.
directory_iterator& operator++();
directory_iterator& operator++(int);
ПараметрыParameters
intint
Число приращений.The number of increments.
См. также разделSee also
Справочник по файлам заголовковHeader Files Reference
<filesystem>
Навигация по файловой системе (C++)File System Navigation (C++)