• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <filesystem>

    std::filesystem::directory_entry::assign

    void assign(const path& p);                      // (1)
    void assign(const path& p, std::error_code& ec); // (2)
    

    概要

    パスを再代入する。

    戻り値

    • (1) : p*thisに保持し、refresh()を実行する
    • (2) : p*thisに保持し、refresh(ec)を実行する

    エラーが発生した場合は、キャッシュされた属性の値は未規定となる (更新前のキャッシュの値のままかもしれないし、キャッシュが破棄されるかもしれない)。(2)の場合は、エラー情報がecに設定される。

    #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::directory_entry x{"dir/a.txt"};
      x.assign("dir/b.txt");
    
      std::cout << x.path() << std::endl;
    }
    

    出力例

    "dir/b.txt"
    

    バージョン

    言語

    • C++17

    処理系