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

std::filesystem::path::extension

path extension() const;

?

(since C++17)

返回路径的文件名组件的扩展。*this...

如果filename()组件包含句点%28。.%29,而不是特殊的文件系统元素点或点点,则延拓从最右边的句点%28开始的子字符串,包括句点%29,直到路径名的结尾。

如果路径名是...,或者如果filename()不包含.字符,则返回空路径。

附加行为可以由附加附加元素%28的文件系统的实现来定义,例如备用数据流或分区数据集名称%29到扩展。

参数

%280%29

返回值

当前路径名的扩展名或空路径(如果有%27 s没有扩展名)。

例外

%280%29

注记

此函数返回的扩展名包括一个句点,以便能够区分以句点%28结束的文件。"."从没有扩展名%28的文件中返回%29""29%。

任何一条路p,,,p.stem()+p.extension() == p.filename()...

二次

代码语言:javascript
复制
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
 
int main()
{
    std::cout << fs::path("/foo/bar.txt").extension() << '\n'
              << fs::path("/foo/bar.").extension() << '\n'
              << fs::path("/foo/bar").extension() << '\n'
              << fs::path("/foo/bar.txt/bar.cc").extension() << '\n'
              << fs::path("/foo/bar.txt/bar.").extension() << '\n'
              << fs::path("/foo/bar.txt/bar").extension() << '\n'
              << fs::path("/foo/.").extension() << '\n'
              << fs::path("/foo/..").extension() << '\n'
              << fs::path("/foo/.hidden").extension() << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
".txt"
"."
""
".cc"
"."
""
""
""
".hidden"

二次

另见

filename

returns the filename path component (public member function)

stem

returns the stem path component (public member function)

replace_extension

replaces the extension (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