std::experi...ace_filename(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

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_filename returns false). 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_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)

🏷️ 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