std::experi...em_complete(3)
Okay bestie, welcome to the std::experi...em_complete(3) page from the C++ Standard Libary manual π (yes, that manual name is staying exactly as it is).
π NAME π
std::experimental::filesystem::absolute, std::experimental::filesystem::system_complete β thatβs the duo, and the page is literally named std::experimental::filesystem::absolute,std::experimental::filesystem::system_complete (the comma is doing its thing, no cap).
πΈ Synopsis πΈ
Defined in header <experimental/filesystem>. Both overloads are (filesystem TS), bestie.
Defined in header <experimental/filesystem>
path absolute( const path& p, const path& base = current_path() (1)
(filesystem TS)
);
path system_complete( const path& p ); (2)
(filesystem TS)
path system_complete( const path& p, error_code& ec );
absolute(1) β returns the absolute path ofprelative tobase, according to these rules:- If
phas both root name and root directory (like"C:\users"), the path is returned, unmodified. - If
phas a root name not followed by a root directory (like"C:text.txt"), thenbaseis inserted betweenpβs root name and the remainder ofp. Formally,p.root_name() / fs::absolute(base).root_directory() / fs::absolute(base).relative_path() / p.relative_path()is returned. - If
phas no root name but has a root directory (like"/var/tmp/file.txt"on a POSIX system or"\users\ABC\Document.doc"on Windows), then the root name ofbase, if it has one, is prepended top. On a POSIX system,pis not modified; on a Windows system,"\users\ABC\Document.doc"becomes"C:\users\ABC\Document.doc". Formally,fs::absolute(base).root_name() / pis returned. - If
phas no root name and no root directory (like"../file.txt"), then the entirebaseis prepended top. Formally,absolute(base) / pis returned.
- If
system_complete(2) β obtains the absolute path that identifies the file that the OS file opening API would access given the pathnamep. On POSIX systems, this is equivalent to (1) with the default base (fs::current_path()). On Windows systems, each logical drive has its own current working directory, and so ifpis not already absolute and has a root name component (like"E:filename.txt"), that driveβs current working directory is used, which may have been set by an earlier executed program.
π Parameters π
pβ path to convert to absolute form.baseβ path (not necessarily absolute) to serve as the starting location.ecβ out-parameter for error reporting in the non-throwing overload.
π¦ Return value π¦
Returns an absolute (although not necessarily canonical) path formed by combining p and base as described above.
π Exceptions π
The overload that does not take an error_code& parameter throws filesystem_error on underlying OS API errors, constructed with p as the first argument, base as the second argument, and the OS error code as the error code argument. std::bad_alloc may be thrown if memory allocation fails.
The overload taking an 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. This overload has noexcept specification:
noexcept
π Notes π
On systems that support root names (e.g. Windows), the result of calling absolute on a relative path that has a root name (e.g. "D:file.txt" when the root name of base is different) will usually result in a non-existent path.
π₯ Example π₯
// Run this code
#include <filesystem>
#include <iostream>
namespace fs = std::experimental::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'
<< "System complete path for " << p << " is "
<< fs::system_complete(p) << '\n';
}
π Possible output π
Current path is "D:/local/ConsoleApplication1"
Absolute path for "C:cl.exe" is "C:/local/ConsoleApplication1/cl.exe"
System complete 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 (function).
π Categories π
- Noindexed pages
- unconditionally noexcept
π Hidden categories π
- Pages with unreviewed unconditional noexcept template
- Pages with unreviewed noexcept template
π Cute little sign-off: this page is from http://cppreference.com, version/date 2024.06.10, and its title is std::experi...em_complete(3). Bye bestie, go make those paths absolute! πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms