std::experi...e_extension(3)

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

πŸ’– std::experi...e_extension(3) πŸ’–

okay so this page is from the C++ Standard Libary manual, and it’s all about std::experimental::filesystem::path::replace_extension. bestie, it’s giving filesystem TS realness, and we’re gonna get into it. ✨

🌸 NAME 🌸

  • std::experimental::filesystem::path::replace_extension β€” yep, std::experimental::filesystem::path::replace_extension (the page repeats its own name, iconic)

✨ Synopsis ✨

path& replace_extension( const path& replacement = path() ); (1)
(filesystem TS)

It replaces the extension with replacement, or removes it when the default value of replacement is used. πŸ’…

Here’s the order of operations, no cap:

  1. Firstly, if this path has an extension(), it is removed.
  2. Then, a dot character is appended if replacement is not empty or does not begin with a dot character.
  3. Then replacement is appended to the path.

πŸŽ€ Parameters πŸŽ€

  • replacement β€” the extension to replace with

πŸ’– Return value πŸ’–

  • *this β€” that’s the whole return, bestie. No extra packaging. 🫢

πŸ”₯ Exceptions πŸ”₯

May throw implementation-defined exceptions. 😭

πŸ¦‹ Example πŸ¦‹

// Run this code

#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;

int main()
{
    fs::path p = "/foo/bar.jpeg";
    std::cout << "Was: " << p << '\n';
    p.replace_extension(".jpg");
    std::cout << "Now: " << p << '\n';
}

🌈 Output 🌈

Was: "/foo/bar.jpeg"
Now: "/foo/bar.jpg"

πŸ‘‘ See also πŸ‘‘

  • extension β€” returns the file extension path component (public member function)
  • filename β€” returns the filename path component (public member function)
  • stem β€” returns the stem path component (public member function)
  • has_extension β€” checks if the corresponding path element is not empty (public member function)

🌟 Category 🌟

  • * Noindexed pages

mwah πŸ’‹ source is http://cppreference.com, version/date is 2024.06.10, and the footer name is std::experi...e_extension(3). periodt. πŸŽ€

πŸ“¦ where this page comes from