std::filesystem::path::replace_filename
文件系统::path::替换[医]文件名
path& replace_filename( const path& replacement | | (since C++17) |
---|
将单个文件名组件替换为replacement
...
相当于以下内容:
二次
remove_filename(
operator/=(replacement
二次
如果路径没有文件名组件%28,则行为未定义has_filename
回报false
29%。
参数
%280%29
返回值
*this
...
例外
%280%29
例
二次
#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"
二次
另见
replace_extension | replaces the extension (public member function) |
---|---|
filename | returns the filename path component (public member function) |
remove_filename | removes filename path component (public member function) |
has_filename | checks if the corresponding path element is not empty (public member function) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。