std::filesystem::path::root_name
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_name
(until C++20)(until C++20)(until C++20)(until C++20)(until C++20)(C++20)
path root_name() const;
 
 (since C++17) 
Returns the root name of the generic-format path. If the path (in generic format) does not include root name, returns path().
[edit] Parameters
(none)
[edit] Return value
The root name 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 name is: " << fs::current_path().root_name() << '\n'; }
Possible output:
Current root name is: "C:"