std::experi...current_path(3)
π NAME π
okay so the header is literally std::experi...current_path(3) because terminal width is a hater π, and the manual name up top is C++ Standard Libary (that spelling is what the page says, not me π
). The actual star of the show is std::experimental::filesystem::current_path β yes bestie, it's a whole mouthful, but we love her.
β¨ Synopsis β¨
Defined in header <experimental/filesystem>
path current_path(); (1) (filesystem TS)
path current_path( error_code& ec ); (2) (filesystem TS)
void current_path( const path& p ); (3) (filesystem TS)
void current_path( const path& p, error_code& ec ); (4) (filesystem TS)
Returns or changes the current path. Iconic dual-purpose behavior, honestly.
- 1,2) Returns the absolute path of the current working directory, obtained as if by POSIX
getcwd. (2) returnspath()if error occurs. - 3,4) Changes the current working directory to
p, as if by POSIXchdir.
πΈ Parameters πΈ
pβ path to change the current working directory to.ecβ out-parameter for error reporting in the non-throwing overloads.
π¦ Return value π¦
- 1,2) Returns the current working directory.
- 3,4)
(none)β literally no return value, bestie.
π₯ Exceptions π₯
- 1,2) The overload that does not take an
error_code¶meter throwsfilesystem_erroron underlying OS API errors, constructed with the OS error code as the error code argument.std::bad_allocmay be thrown if memory allocation fails. The overload taking anerror_code¶meter sets it to the OS API error code if an OS API call fails, and executesec.clear()if no errors occur. This overload hasnoexceptspecification:noexcept. - 3,4) The overload that does not take an
error_code¶meter throwsfilesystem_erroron underlying OS API errors, constructed withpas the first argument and the OS error code as the error code argument.std::bad_allocmay be thrown if memory allocation fails. The overload taking anerror_code¶meter sets it to the OS API error code if an OS API call fails, and executesec.clear()if no errors occur. This overload hasnoexceptspecification:noexcept.
π Notes π
The current working directory is the directory that is used as the starting location in path resolution for relative paths. Single current working directory is associated with entire process.
The current working directory is a dangerous global state of the program. Behavior of various file input/output related functions are affected by the value of the current path. The current path may be unexpectedly changed by any component of the program, including various external libraries or other threads.
bestie, this is not a cute little local variable. it's global state. treat it with respect ππ
π See also π
This section is incomplete. Yes, that is literally what it says. π
π Categories π
- Noindexed pages
- unconditionally noexcept
- Todo without reason
π«Ά Hidden categories π«Ά
- Pages with unreviewed unconditional noexcept template
- Pages with unreviewed noexcept template
that's the page, bestie π source: http://cppreference.com Β· date/version: 2024.06.10 Β· page: std::experi...current_path(3). mwah π
π¦ 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