名稱空間
變體
操作

std::filesystem::path::replace_filename

來自 cppreference.com
< cpp‎ | filesystem‎ | path
 
 
 
 
path& replace_filename( const path& replacement );
(C++17 起)

replacement 替換單個檔名元件。

等價於:remove_filename(); return operator/=(replacement);

目錄

[編輯] 引數

replacement - 用於替換檔名元件的 path

[編輯] 返回值

*this

[編輯] 異常

可能丟擲實現定義的異常。

[編輯] 示例

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

輸出

"/bar"
"/bar"
"pub"

[編輯] 參閱

替換副檔名
(公開成員函式) [編輯]
返回檔名路徑元件
(公開成員函式) [編輯]
刪除檔名路徑元件
(公開成員函式) [編輯]
檢查相應路徑元素是否不為空
(公開成員函式)