名稱空間
變體
操作

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

來自 cppreference.com
< cpp‎ | filesystem‎ | path
 
 
 
 
friend path operator/( const path& lhs, const path& rhs );
(C++17 起)

若適當,則使用偏好的目錄分隔符連線二個路徑分量(細節見 operator/=)。

等效於返回 path(lhs) /= rhs

此函式對常規的非限定限定查詢不可見,只能在 std::filesystem::path 是引數的關聯類時由實參依賴查詢找到。這在存在 using-directive using namespace std::filesystem; 時,阻止不期待的轉換。

目錄

[編輯] 引數

lhs, rhs - 要連線的路徑

[編輯] 返回值

路徑連線的結果。

[編輯] 示例

#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
}

可能的輸出

Windows specific output:
"C:" / "Users" / "batman" == "C:Users\\batman"
 
Linux etc specific output:
"/home" / "tux" / ".fonts" == "/home/tux/.fonts"

[編輯] 缺陷報告

下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。

缺陷報告 應用於 釋出時的行為 正確的行為
LWG 3065 C++17 在有 using-directive 時,允許連線所有可轉換為 path 的東西 設為隱藏友元

[編輯] 參閱

用目錄分隔符向路徑追加元素
(公開成員函式) [編輯]