std::filesystem::relative, std::filesystem::proximate
Min standard notice:
Header: <filesystem>
- 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
p: an existing pathbase: base path, against which p will be made relative/proximateec: error code to store error status to
# 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");
}