std::filesystem::path::filename
文件系统::path::filename
path filename() const; | | (since C++17) |
---|
返回路径的文件名组件。
相当于empty() ? path() : *--end()
...
参数
%280%29
返回值
路径标识的文件名。
例外
%280%29
例
二次
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
std::cout << fs::path("/foo/bar.txt").filename() << '\n'
<< fs::path("/foo/.bar").filename() << '\n'
<< fs::path("/foo/bar/").filename() << '\n'
<< fs::path("/foo/.").filename() << '\n'
<< fs::path("/foo/..").filename() << '\n'
<< fs::path(".").filename() << '\n'
<< fs::path("..").filename() << '\n'
<< fs::path("/").filename() << '\n';
}
二次
产出:
二次
"bar.txt"
".bar"
"."
"."
".."
"."
".."
"/"
二次
另见
extension | returns the file extension path component (public member function) |
---|---|
stem | returns the stem path component (public member function) |
replace_filename | replaces the last path component with another path (public member function) |
has_filename | checks if the corresponding path element is not empty (public member function) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。