close
名前空間
変種

std::filesystem::path::replace_filename

提供: cppreference.com
 
 
 
 
<tbody> </tbody>
path& replace_filename( const path& replacement );
(C++17以上)

単一のファイル名部分を replacement で置き換えます。

以下と同等です。

remove_filename();
operator/=(replacement);

パスがファイル名部分を持たない (has_filenamefalse を返す) 場合、動作は未定義です。

引数

(なし)

戻り値

*this

例外

(なし)

#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;

int main()
{

    std::cout << fs::path("/foo").replace_filename("bar") << '\n'
              << fs::path("/").replace_filename("bar") << '\n';
}

出力:

"/bar"
"bar"

関連項目

拡張子を置換します
(パブリックメンバ関数) [edit]
パスのファイル名部分を返します
(パブリックメンバ関数) [edit]
パスのファイル名部分を削除します
(パブリックメンバ関数) [edit]
対応するパス要素が空でないかどうか調べます
(パブリックメンバ関数)