std::filesystem::path::root_path
From cppreference.com
< cpp | filesystem | path
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
std::filesystem::path
path::root_path
(until C++20)(until C++20)(until C++20)(until C++20)(until C++20)(C++20)
path root_path() const;
(since C++17)
Returns the root path of the path. If the path does not include root path, returns path().
Effectively returns root_name() / root_directory().
[edit] Parameters
(none)
[edit] Return value
The root path of the path.
[edit] Exceptions
May throw implementation-defined exceptions.
[edit] Example
Run this code
#include <filesystem> #include <iostream> namespace fs = std::filesystem; int main() { std::cout << "Current root path is: " << fs::current_path().root_path() << '\n'; }
Possible output:
Current root path is: "C:\"