首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::filesystem::path::replace_extension

path& replace_extension( const path& replacement = path() );

(1)

(since C++17)

将扩展替换为replacement的默认值时移除replacement被使用了。

首先,如果这条路径有一个extension(),它被移除了。

然后,如果replacement不是空的,也不是以点字符开头的。

然后replacement被附加到路径上。

参数

replacement

-

the extension to replace with

返回值

*this...

例外

%280%29

二次

代码语言:javascript
复制
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
 
int main()
{
    fs::path p = "/foo/bar.jpeg";
    std::cout << "Was: " << p << '\n';
    p.replace_extension(".jpg");
    std::cout << "Now: " << p.replace_extension(".jpg") << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
Was: "/foo/bar.jpeg"
Now: "/foo/bar.jpg"

二次

另见

extension

returns the file extension path component (public member function)

filename

returns the filename path component (public member function)

stem

returns the stem path component (public member function)

has_extension

checks if the corresponding path element is not empty (public member function)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com