std::filesystem::operator/(std::filesystem::path)

Concatenates two path components using the preferred directory separator if appropriate (see operator/= for details).

# Declarations

friend path operator/( const path& lhs, const path& rhs );

(since C++17)

# Parameters

# Return value

The result of path concatenation.

# Example

#include <filesystem>
#include <iostream>
 
int main()
{
#   if defined(_WIN32) // see e.g. stackoverflow.com/questions/142508
 
    std::filesystem::path p = "C:";
 
    std::cout << "\"C:\" / \"Users\" / \"batman\" == " << p / "Users" / "batman" << '\n';
 
#   else // __linux__ etc
 
    std::filesystem::path p = "/home";
 
    std::cout << "\"/home\" / \"tux\" / \".fonts\" == " << p / "tux" / ".fonts" << '\n';
 
#   endif
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 3065C++17allowed concatenating everything convertible to path in the presence of a using-directivemade hidden friend

# See also