std::filesystem::absolute
Min standard notice:
Header: <filesystem>
Returns a path referencing the same file system location as p, for which filesystem::path::is_absolute() is true.
# Declarations
path absolute( const std::filesystem::path& p );
(since C++17)
path absolute( const std::filesystem::path& p, std::error_code& ec );
(since C++17)
# Parameters
p: path to convert to absolute formec: out-parameter for error reporting in the non-throwing overload
# Return value
Returns an absolute (although not necessarily canonical) pathname referencing the same file as p.
# Notes
Implementations are encouraged to not consider p not existing to be an error.
For POSIX-based operating systems, std::filesystem::absolute(p) is equivalent to std::filesystem::current_path() / p except for when p is the empty path.
For Windows, std::filesystem::absolute may be implemented as a call to GetFullPathNameW.
# Example
#include <filesystem>
#include <iostream>
namespace fs = std::filesystem;
int main()
{
std::filesystem::path p = "foo.c";
std::cout << "Current path is " << std::filesystem::current_path() << '\n';
std::cout << "Absolute path for " << p << " is " << fs::absolute(p) << '\n';
}