std::experi...parent_path(3)
π std::experi...parent_path(3) π
okay so welcome to the std::experi...parent_path(3) page from the C++ Standard Libary manual β yes bestie, that's the manual name, typo and all, and I folded it in up here instead of copy-pasting the whole header line. This one is all about std::experimental::filesystem::path::parent_path, and it's lowkey iconic. π
πΈ NAME πΈ
std::experimental::filesystem::path::parent_pathβstd::experimental::filesystem::path::parent_path
the original name line does the double-repeat thing, so we're keeping that energy fr fr π«Ά
β¨ Synopsis β¨
path parent_path() const; (filesystem TS)
Okay so this is the filesystem TS version, no cap. It returns the path to the parent directory. But plot twist: it returns an empty path if empty() or there's only a single element in the path β specifically when begin() == --end(). π
The resulting path is constructed by appending all elements in the range [begin(), --end()) to an empty path. That's the whole construction vibe, periodt. β¨
π Parameters π
(none)β literally no parameters, she takes none, slay.
π Return value π
The path to the parent directory. That's it, that's the return value, main character energy. π
π Exceptions π
May throw implementation-defined exceptions. Translation: the implementation gets to decide, so don't come for me if it throws β that's the caveat and we're keeping it crystal clear. π«Ά
π¦ Example π¦
// Run this code
#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
int main()
{
for (fs::path p : {"/var/tmp/example.txt", "/", "/var/tmp/."})
std::cout << "The parent path of " << p
<< " is " << p.parent_path() << '\n';
}
Possible output:
The parent path of "/var/tmp/example.txt" is "/var/tmp"
The parent path of "/" is ""
The parent path of "/var/tmp/." is "/var/tmp"
π See also π
This section is incomplete β bestie, they literally left it blank, not me. π
π Categories π
- Noindexed pages
- Todo without reason
source/version/date sign-off: this page comes from http://cppreference.com, dated 2024.06.10, and its footer handle is std::experi...parent_path(3) β folded into this cute little sign-off instead of copy-pasted, 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