std::filesy...th::filename(3)
π std::filesystem::path::filename π
okay bestie, welcome to the std::filesy...th::filename(3) page from the C++ Standard Libary manual β yep, manual name folded in right here, no boring header line for us π
β¨
π NAME π
std::filesystem::path::filename-std::filesystem::path::filename
like, that's the name and also the name again. iconic. π«Ά
π¦ Synopsis π¦
path filename() const; (since C++17)
It returns the generic-format filename component of the path. no cap.
It's equivalent to relative_path().empty() ? path() : *--end() β literally that.
πΈ Parameters πΈ
(none) β zero, zilch, nada, no parameters bestie. π
β¨ Return value β¨
The filename identified by the path. that's it, that's the tea. periodt.
π₯ Exceptions π₯
β οΈ May throw implementation-defined exceptions. so like, keep that in mind, mwah.
π§ Example π§
// Run this code
#include <filesystem>
#include <iostream>
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'
<< fs::path("//host").filename() << '\n';
}
π Output: π
"bar.txt"
".bar"
""
"."
".."
"."
".."
""
"host"
π See also π
extensionβ returns the file extension path component (public member function)stemβ returns the stem path component (filename without the final extension) (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)
byeee bestie π«Άπ β source is http://cppreference.com, version/date is 2024.06.10, and this cutie page is std::filesy...th::filename(3). mwah, slay, periodt β¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms