名稱空間
變體
操作

std::experimental::filesystem::path::append, std::experimental::filesystem::path::operator/=

來自 cppreference.com
< cpp‎ | experimental‎ | fs‎ | path
 
 
實驗性
技術規範
檔案系統庫 (檔案系統 TS)
庫基礎 (庫基礎 TS)
庫基礎 2 (庫基礎 TS v2)
庫基礎 3 (庫基礎 TS v3)
並行性擴充套件 (並行性 TS)
並行性擴充套件 2 (並行性 TS v2)
併發性擴充套件 (併發性 TS)
併發擴充套件 2 (併發 TS v2)
概念 (概念 TS)
範圍 (範圍 TS)
反射 (反射 TS)
數學特殊函式 (特殊函式 TR)
實驗性非 TS
模式匹配
線性代數
std::execution
契約
2D 圖形
 
 
 
path& operator/=( const path& p );
(1) (filesystem TS)
template< class Source >
path& operator/=( const Source& source );
(2) (filesystem TS)
template< class Source >
path& append( const Source& source );
(3) (filesystem TS)
template< class InputIt >
path& append( InputIt first, InputIt last );
(4) (filesystem TS)
1) 首先,將首選目錄分隔符附加到 this,除非以下任何條件為真:
* 分隔符是多餘的(*this 已經以分隔符結尾)。
* *this 為空,或者新增它會以其他方式將相對路徑轉換為絕對路徑。
* p 是空路徑。
* p.native() 以目錄分隔符開頭。
然後,將 p.native() 附加到由 *this 維護的路徑名。
2,3)(1) 相同,但接受任何 std::basic_string、以空字元結尾的多字元字串,或指向以空字元結尾的多字元序列的輸入迭代器。
4)(1) 相同,但接受指定多字元字串的任何迭代器對。

目錄

[編輯] 引數

p - 要附加的路徑名
source - std::basic_string、以空字元結尾的多字元字串,或指向以空字元結尾的多字元序列的輸入迭代器,表示一個路徑名(可移植格式或本地格式)
first, last - 一對 LegacyInputIterators,指定表示路徑名的多字元序列
型別要求
-
InputIt 必須滿足 LegacyInputIterator 的要求。
-
InputIt 的值型別必須是編碼字元型別之一(charwchar_tchar16_tchar32_t)。

[編輯] 返回值

*this

[編輯] 異常

在底層作業系統 API 錯誤時可能丟擲 filesystem_error,如果記憶體分配失敗則丟擲 std::bad_alloc

[編輯] 示例

#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
 
int main()
{
    fs::path p1 = "C:";
    p1 /= "Users"; // does not insert a separator
                   // "C:Users" is a relative path in Windows
                   // adding directory separator would turn it to an absolute path
    std::cout << "\"C:\" / \"Users\" == " << p1 << '\n';
    p1 /= "batman"; // inserts fs::path::preferred_separator, '\' on Windows
    std::cout << "\"C:\" / \"Users\" / \"batman\" == " << p1 << '\n';
}

可能的輸出

"C:" / "Users" == "C:Users"
"C:" / "Users" / "batman" == "C:Users\batman"

[編輯] 參閱

連線兩個路徑而不引入目錄分隔符
(public member function) [編輯]
用目錄分隔符連線兩個路徑
(function) [編輯]