• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <filesystem>

    std::filesystem::recursive_directory_iterator::increment

    recursive_directory_iterator& increment(std::error_code& ec);
    

    概要

    イテレータを進める。

    効果

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

    エラーが発生した場合、ecにエラー情報が書き込まれる。

    戻り値

    *this

    #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;
    
      std::error_code ec;
      it.increment(ec);
    
      if (!ec) {
        std::cout << "after  : " << it->path() << std::endl;
      }
      else {
        std::cout << "increment error : " << ec.message() << std::endl;
      }
    }
    

    出力

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

    バージョン

    言語

    • C++17

    処理系

    参照