std::filesy...ace_filename(3)
π NAME
okay so bestie, welcome to the std::filesystem::path::replace_filename glow-up page β¨ this is straight out of the C++ Standard Libary manual β yes that's literally the manual name, i don't make the rules β and it's filed under std::filesy...ace_filename(3) if you're searching for it π
std::filesystem::path::replace_filename β std::filesystem::path::replace_filename (yes the name is the whole name, she said what she said π
)
πΈ SYNOPSIS
path& replace_filename( const path& replacement ); (since C++17)
so what does she actually do? she replaces a single filename component with replacement π¦ that's the whole vibe, no cap.
it's literally equivalent to this little two-step:
remove_filename(); return operator/=(replacement);
like she removes the old filename, then slaps the new one on with /= β iconic, efficient, ate π
π PARAMETERS
replacementβ the path you're using to replace the filename component with π«Ά that's it, that's the whole parameter.
β¨ RETURN VALUE
*this β she returns herself π
main character energy fr fr.
π₯ EXCEPTIONS
may throw implementation-defined exceptions π so like, don't @ her if your particular stdlib decides to be dramatic. it's giving "your mileage may vary" but make it C++.
π EXAMPLE
go ahead and run this code, bestie π
#include <filesystem>
#include <iostream>
namespace fs = std::filesystem;
int main()
{
std::cout << fs::path("/foo").replace_filename("bar") << '\n'
<< fs::path("/").replace_filename("bar") << '\n'
<< fs::path("").replace_filename("pub") << '\n';
}
β Output
"/bar"
"/bar"
"pub"
look at that β "/foo" becomes "/bar", the root "/" also becomes "/bar", and the empty path becomes "pub" π¦ three little glow-ups, all slaying π
π SEE ALSO
replace_extensionβ replaces the extension (public member function) πfilenameβ returns the filename path component (public member function) πΈremove_filenameβ removes filename path component (public member function) πhas_filenameβ checks if the corresponding path element is not empty (public member function) π
ngl bestie, always double-check your implementation-defined exceptions before you ship β she's cute but she's not promising you anything π
that's the whole page, periodt π
β¨ sourced from http://cppreference.com, dated 2024.06.10 β mwah, go write some filesystem code, you've got this π«Άππ¦
π¦ 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