名前空間
変種
操作

std::filesystem::filesystem_error::path1, std::filesystem::filesystem_error::path2

From cppreference.com
 
 
 
filesystem_error
メンバ関数
filesystem_error::path1filesystem_error::path2
std::system_error から継承
 
const std::filesystem::path& path1() const noexcept;
(C++17以降)
const std::filesystem::path& path2() const noexcept;
(C++17以降)

例外オブジェクトに格納されていたパスを返します。

[編集] パラメータ

(なし)

[編集] 戻り値

コンストラクタによって格納された path パラメータのコピーへの参照。

[編集]

#include <cstdio>
#include <filesystem>
#include <iostream>
 
int main()
{
    const std::filesystem::path old_p{std::tmpnam(nullptr)},
                                new_p{std::tmpnam(nullptr)};
    try {
        std::filesystem::rename(old_p, new_p); // throws since old_p does not exist
    }
    catch(std::filesystem::filesystem_error const& ex) {
        std::cout
            << "what():  " << ex.what() << '\n'
            << "path1(): " << ex.path1() << '\n'
            << "path2(): " << ex.path2() << '\n';
    }
}

実行結果の例

what():  filesystem error: cannot rename: No such file or directory [/tmp/fileIzzRLB] [/tmp/fileiUDWlV]
path1(): "/tmp/fileIzzRLB"
path2(): "/tmp/fileiUDWlV"
English 日本語 中文(简体) 中文(繁體)