std::experi...th::filename(3)
π std::experi...th::filename(3) π
okay bestie, welcome to the C++ Standard Libary manual, section 3 β this page is all about std::experi...th::filename, aka std::experimental::filesystem::path::filename. the way this is a whole member function just for the filename componentβ¦ iconic.
πΈ NAME πΈ
std::experi...th::filename β std::experimental::filesystem::path::filename. that's the name, no cap.
β¨ Synopsis β¨
path filename() const; (filesystem TS)
Returns the filename component of the path.
Itβs equivalent to empty() ? path() : *--end() β literally that expression, bestie, donβt @ me.
π Parameters π
There are none. Zero. Nada. The page says (none), and it means it.
π¦ Return value π¦
The filename identified by the path. thatβs it, thatβs the return value.
π Exceptions π
May throw implementation-defined exceptions. so yeah, keep that in mind β implementation-defined is doing a lot of heavy lifting there.
π Example π
// Run this code
#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::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';
}
π₯ Output π₯
"bar.txt"
".bar"
"."
"."
".."
"."
".."
"/"
π See also π
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)
π Category π
- Noindexed pages
xoxo, your local Unix bestie π
β source: http://cppreference.com; version/date: 2024.06.10. fr fr, thatβs the whole page.
π¦ 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