| Classes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| File types | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Defined in header <filesystem> | ||
path relative(conststd::filesystem::path& p, std::error_code& ec); | (1) | (since C++17) |
path relative(conststd::filesystem::path& p, conststd::filesystem::path& base=std::filesystem::current_path()); | (2) | (since C++17) |
path relative(conststd::filesystem::path& p, conststd::filesystem::path& base, | (3) | (since C++17) |
path proximate(conststd::filesystem::path& p, std::error_code& ec); | (4) | (since C++17) |
path proximate(conststd::filesystem::path& p, conststd::filesystem::path& base=std::filesystem::current_path()); | (5) | (since C++17) |
path proximate(conststd::filesystem::path& p, conststd::filesystem::path& base, | (6) | (since C++17) |
Contents |
| p | - | an existing path |
| base | - | base path, against whichp will be made relative/proximate |
| ec | - | error code to store error status to |
Any overload not markednoexcept may throwstd::bad_alloc if memory allocation fails.
#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");}
Possible output:
x: "/a/b/c"y: "/a/b"relative(x, y): "c"proximate(x, y): "c" x: "/a/c"y: "/a/b"relative(x, y): "../c"proximate(x, y): "../c" x: "c"y: "/a/b"relative(x, y): ""proximate(x, y): "c" x: "/a/b"y: "c"relative(x, y): ""proximate(x, y): "/a/b"
(C++17) | represents a path (class)[edit] |
(C++17) | composes an absolute path (function)[edit] |
(C++17) | composes a canonical path (function)[edit] |
| converts path to normal form converts path to relative form converts path to proximate form (public member function of std::filesystem::path)[edit] |