std::filesystem::relative, std::filesystem::proximate

Header: <filesystem>

  1. Returns relative(p, current_path(), ec).

# Declarations

path relative( const std::filesystem::path& p,
std::error_code& ec );

(since C++17)

path relative( const std::filesystem::path& p,
const std::filesystem::path& base = std::filesystem::current_path() );

(since C++17)

path relative( const std::filesystem::path& p,
const std::filesystem::path& base,
std::error_code& ec );

(since C++17)

path proximate( const std::filesystem::path& p,
std::error_code& ec );

(since C++17)

path proximate( const std::filesystem::path& p,
const std::filesystem::path& base = std::filesystem::current_path() );

(since C++17)

path proximate( const std::filesystem::path& p,
const std::filesystem::path& base,
std::error_code& ec );

(since C++17)

# Parameters

# Example

#include <filesystem>
#include <iostream>
 
void show(std::filesystem::path x, std::filesystem::path y)
{
    std::cout << "x:\t\t " << x << "\ny:\t\t " << y << '\n'
              << "relative(x, y):  "
              << std::filesystem::relative(x, y) << '\n'
              << "proximate(x, y): "
              << std::filesystem::proximate(x, y) << "\n\n";
}
 
int main()
{
    show("/a/b/c", "/a/b");
    show("/a/c", "/a/b");
    show("c", "/a/b");
    show("/a/b", "c");
}

# See also