std::filesy...lative_path(3)

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

πŸ’– NAME πŸ’–

std::filesy...lative_path(3) β€” that’s the manual page name, bestie β€” and it’s from the C++ Standard Libary. The NAME situation is literally:

std::filesystem::path::relative_path - std::filesystem::path::relative_path

Yes, it’s giving iconic repetition. πŸ’…

✨ Synopsis ✨

path relative_path() const;  (since C++17)

This is the public member function that returns the path relative to root-path β€” like, a pathname composed of every generic-format component of *this after root-path. If *this is an empty path, it returns an empty path. Clean, simple, slay.

πŸŽ€ Parameters πŸŽ€

(none) β€” she takes no arguments. Low-maintenance icon behavior.

🌸 Return value 🌸

Path relative to the root path. That’s the whole vibe.

πŸ¦‹ Exceptions πŸ¦‹

May throw implementation-defined exceptions. So yes, exceptions can happen, and exactly which ones is implementation-defined β€” not me guessing, fr fr. πŸ™ˆ

πŸ”₯ Example πŸ”₯

// Run this code

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

int main()
{
    fs::path p = fs::current_path();

    std::cout << "The current path " << p << " decomposes into:\n"
              << "root-path " << p.root_path() << '\n'
              << "relative path " << p.relative_path() << '\n';
}

Possible output:

The current path "C:\Users\abcdef\Local Settings\temp" decomposes into:
root-path "C:\"
relative path "Users\abcdef\Local Settings\temp"

πŸ‘‘ See also πŸ‘‘

  • root_name β€” returns the root-name of the path, if present (public member function)
  • root_directory β€” returns the root directory of the path, if present (public member function)
  • root_path β€” returns the root path of the path, if present (public member function)

Okay that’s the whole page, bestie! Cute sign-off with the source/version/date details: http://cppreference.com, 2024.06.10, and the page name std::filesy...lative_path(3) β€” periodt. πŸ’–βœ¨

πŸ“¦ where this page comes from