std::experi...ace_filename(3)
okay bestie, we're opening std::experi...ace_filename(3) from the C++ Standard Libary manual β yes, that's the spelling up top, and it's iconic π
. This page is all about std::experimental::filesystem::path::replace_filename, and the NAME section is serving pure twin energy: std::experimental::filesystem::path::replace_filename β std::experimental::filesystem::path::replace_filename. Not me, that's just what it says π.
πΈ NAME πΈ
std::experimental::filesystem::path::replace_filename β std::experimental::filesystem::path::replace_filename
π¦ Synopsis π¦
path& replace_filename( const path& replacement ); (filesystem TS)
Replaces a single filename component with replacement.
Equivalent to the following:
remove_filename();
operator/=(replacement);
β οΈ Undefined behavior alert: the behavior is undefined if the path has no filename component (has_filenamereturnsfalse). That's a big yikes β undefined is undefined, no cap.
π Parameters π
(none) β that's literally the whole section. No extra details, just (none).
β Return value β
*this
π Exceptions π
May throw implementation-defined exceptions.
π§ Example π§
// Run this code
#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
int main()
{
std::cout << fs::path("/foo").replace_filename("bar") << '\n'
<< fs::path("/").replace_filename("bar") << '\n';
}
Output:
"/bar"
"bar"
π₯ See also π₯
replace_extensionreplaces the extension (public member function)filenamereturns the filename path component (public member function)remove_filenameremoves filename path component (public member function)has_filenamechecks if the corresponding path element is not empty (public member function)
π·οΈ Category π·οΈ
The category tag is literally: * Noindexed pages
kisses from http://cppreference.com β version/date vibes: 2024.06.10 β and the page is std::experi...ace_filename(3) π«Ά
π¦ 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