std::filesy...lative_path(3)
π 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
- 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