• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    function
    <filesystem>

    std::filesystem::recursive_directory_iterator::operator++

    recursive_directory_iterator& operator++();
    recursive_directory_iterator operator++(int);
    

    概要

    イテレータを進める。

    効果

    コンストラクタで指定されたstd::filesystem::directory_optionsの値に基づいて、次のファイルを指すようイテレータを進める。

    例外が発生した場合は、終端を指す状態になる。

    戻り値

    • (1) : 進めたあとのイテレータ自身への参照を返す
    • (2) : 進める前のイテレータのコピーを返す

    例外

    ファイルシステムがエラーを報告する場合がある。エラーが発生した場合は、std::filesystem::filesystem_error例外を送出する

    #include <iostream>
    #include <filesystem>
    #include <fstream>
    
    namespace fs = std::filesystem;
    
    int main()
    {
      fs::create_directory("dir");
      std::ofstream{"dir/a.txt"};
      std::ofstream{"dir/b.txt"};
    
      fs::recursive_directory_iterator it{"dir"};
    
      std::cout << "before : " << it->path() << std::endl;
      ++it;
      std::cout << "after  : " << it->path() << std::endl;
    }
    

    出力

    before : "dir/b.txt"
    after  : "dir/a.txt"
    

    バージョン

    言語

    • C++17

    処理系