std::filesystem::absolute (3) - Linux Manuals
std::filesystem::absolute: std::filesystem::absolute
Command to display std::filesystem::absolute
manual in Linux: $ man 3 std::filesystem::absolute
NAME
std::filesystem::absolute - std::filesystem::absolute
Synopsis
Defined in header <filesystem>
path absolute(const std::filesystem::path& p); (since C++17)
path absolute(const std::filesystem::path& p, std::error_code& ec);
Returns a path referencing the same file system location as p, for which is_absolute() is true. The non-throwing overload returns default-constructed path if an error occurs.
Parameters
p - path to convert to absolute form
ec - 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
Exceptions
The overload that does not take a std::error_code& parameter throws filesystem_error on underlying OS API errors, constructed with p as the first path argument and the OS error code as the error code argument. The overload taking a std::error_code& parameter sets it to the OS API error code if an OS API call fails, and executes ec.clear() if no errors occur. Any overload not marked noexcept may throw std::bad_alloc if memory allocation fails.
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
For Windows, absolute may be implemented as a call to GetFullPathNameW.
Example
// Run this code
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
fs::path p = "C:cl.exe";
std::cout << "Current path is " << fs::current_path() << '\n'
<< "Absolute path for " << p << " is " << fs::absolute(p) << '\n';
// actual location: "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\cl.exe"
}
Possible output:
Current path is "D:/local/ConsoleApplication1"
Absolute path for "C:cl.exe" is "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\cl.exe"
See also
canonical composes a canonical path
weakly_canonical (function)
(C++17)
relative composes a relative path
proximate (function)
(C++17)
Pages related to std::filesystem::absolute
- std::filesystem::begin(directory_iterator),std::filesystem::end(directory_iterator) (3) - std::filesystem::begin(directory_iterator),std::filesystem::end(directory_iterator)
- std::filesystem::begin(recursive_directory_iterator), (3) - std::filesystem::begin(recursive_directory_iterator),
- std::filesystem::begin(recursive_directory_iterator),std::filesystem::end(recursive_directory_iterator) (3) - std::filesystem::begin(recursive_directory_iterator),std::filesystem::end(recursive_directory_iterator)
- std::filesystem::canonical,std::filesystem::weakly_canonical (3) - std::filesystem::canonical,std::filesystem::weakly_canonical
- std::filesystem::copy (3) - std::filesystem::copy
- std::filesystem::copy_file (3) - std::filesystem::copy_file
- std::filesystem::copy_options (3) - std::filesystem::copy_options
- std::filesystem::copy_symlink (3) - std::filesystem::copy_symlink
- std::filesystem::create_directory,std::filesystem::create_directories (3) - std::filesystem::create_directory,std::filesystem::create_directories
- std::filesystem::create_hard_link (3) - std::filesystem::create_hard_link
- std::filesystem::create_symlink,std::filesystem::create_directory_symlink (3) - std::filesystem::create_symlink,std::filesystem::create_directory_symlink
- std::filesystem::current_path (3) - std::filesystem::current_path
- std::filesystem::directory_entry (3) - std::filesystem::directory_entry
- std::filesystem::directory_entry::assign (3) - std::filesystem::directory_entry::assign
- std::filesystem::directory_entry::directory_entry (3) - std::filesystem::directory_entry::directory_entry
- std::filesystem::directory_entry::exists (3) - std::filesystem::directory_entry::exists
- std::filesystem::directory_entry::file_size (3) - std::filesystem::directory_entry::file_size
- std::filesystem::directory_entry::hard_link_count (3) - std::filesystem::directory_entry::hard_link_count
- std::filesystem::directory_entry::is_block_file (3) - std::filesystem::directory_entry::is_block_file
- std::filesystem::directory_entry::is_character_file (3) - std::filesystem::directory_entry::is_character_file
- std::filesystem::directory_entry::is_directory (3) - std::filesystem::directory_entry::is_directory