Namespaces
Variants

std::experimental::filesystem::path:: replace_filename

From cppreference.net
path & replace_filename ( const path & replacement ) ;
(ファイルシステム TS)

単一のファイル名コンポーネントを replacement で置き換えます。

以下と同等:

remove_filename();
operator/=(replacement);

ファイル名コンポーネントが存在しない場合の動作は未定義です( has_filename false を返す場合)。

目次

パラメータ

(なし)

戻り値

* this

例外

実装定義の例外をスローする可能性があります。

#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
int main()
{
    std::cout << fs::path("/foo").replace_filename("bar") << '\n'
              << fs::path("/").replace_filename("bar") << '\n';
}

出力:

"/bar"
"bar"

関連項目

拡張子を置換する
(公開メンバ関数)
ファイル名パスコンポーネントを返す
(公開メンバ関数)
ファイル名パスコンポーネントを削除する
(公開メンバ関数)
対応するパス要素が空でないかチェックする
(公開メンバ関数)