std::filesy...ot_directory(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

okay so bestie, welcome to the std::filesy...ot_directory(3) page from the C++ Standard Libary (yes, that spelling is in the building 😭). We’re talking about std::filesystem::path::root_directory, and it’s lowkey a tiny member function with main-character energy. Let’s go. πŸ’…

🌸 NAME 🌸

std::filesystem::path::root_directory β€” and the description is literally std::filesystem::path::root_directory again. No cap, that’s the whole NAME section: the function and itself. πŸ’–

✨ Synopsis ✨

path root_directory() const;  (since C++17)

Returns the root directory of the generic-format path. If the path (in generic format) does not include root directory, it returns path(). That detail is doing a lot of work, so don’t skip it, bestie. 🫢

πŸŽ€ Parameters πŸŽ€

  • (none) β€” literally no parameters. Not a one. It’s giving β€œI need nothing from you” energy. ✨

πŸ’– Return value πŸ’–

The root directory of the path. That’s it. That’s the return value. Iconic, honestly. πŸ‘‘

πŸ¦‹ Exceptions πŸ¦‹

May throw implementation-defined exceptions. So yeah, the implementation gets to decide the drama hereβ€”handle it accordingly. 😭

🌈 Example 🌈

// Run this code

#include <filesystem>
#include <iostream>
namespace fs = std::filesystem;

int main()
{
    fs::path p = fs::current_path();

    std::cout << "The current path " << p << " decomposes into:\n"
              << "root name " << p.root_name() << '\n'
              << "root directory " << p.root_directory() << '\n'
              << "relative path " << p.relative_path() << '\n';
}

Possible output:

The current path "C:\Users\abcdef\Local Settings\temp" decomposes into:
root name "C:"
root directory "\"
relative path "Users\abcdef\Local Settings\temp"

πŸ‘‘ See also πŸ‘‘

  • root_name β€” returns the root-name of the path, if present (public member function) 🌟
  • root_path β€” returns the root path of the path, if present (public member function) 🌟

kiss kiss, bestie: this page’s source is http://cppreference.com, its version/date is 2024.06.10, and the manual page is std::filesy...ot_directory(3). slay. πŸ’…βœ¨

πŸ“¦ where this page comes from