std::experimental::filesystem::path::concat, std::experimental::filesystem::path::operator+=
來自 cppreference.com
< cpp | experimental | fs | path
path& operator+=( const path& p ); |
(1) | (filesystem TS) |
path& operator+=( const string_type& str ); |
(2) | (filesystem TS) |
path& operator+=( const value_type* ptr ); |
(3) | (filesystem TS) |
path& operator+=( value_type x ); |
(4) | (filesystem TS) |
template< class Source > path& operator+=( const Source& source ); |
(5) | (filesystem TS) |
template< class CharT > path& operator+=( CharT x ); |
(6) | (filesystem TS) |
template< class Source > path& concat( const Source& source ); |
(7) | (filesystem TS) |
template< class InputIt > path& concat( InputIterator first, InputIterator last ); |
(8) | (filesystem TS) |
連線當前路徑和引數。
5) 同 (1),但結果的 native() 是原始 native() 和由 source 表示的序列(可以是可移植或原生格式)的連線,source 可以是 std::basic_string、以 null 結尾的多字元字串,或指向以 null 結尾的多字元序列的輸入迭代器。
6) 同 (4),但可能執行字元轉換。
7) 同 (5)。
8) 同 (5),但序列由指定多字元字串的任何迭代器對錶示。
目錄 |
[編輯] 引數
p | - | 要附加的路徑 |
str | - | 要附加的字串 |
ptr | - | 指向要附加的以 null 結尾字串開頭的指標 |
x | - | 要附加的單個字元 |
source | - | std::basic_string、以 null 結尾的多字元字串,或指向以 null 結尾的多字元序列的輸入迭代器,表示路徑名(可移植或原生格式) |
first, last | - | 指定表示路徑名的多字元序列的 LegacyInputIterator 對 |
型別要求 | ||
-InputIt 必須滿足 LegacyInputIterator 的要求。 | ||
-InputIt 的值型別必須是編碼字元型別之一(char、wchar_t、char16_t 和 char32_t)。 | ||
-CharT 必須是編碼字元型別之一(char、wchar_t、char16_t 和 char32_t)。 |
[編輯] 返回值
*this
[編輯] 異常
如果底層 OS API 錯誤或記憶體分配失敗,可能會丟擲 filesystem_error 或 std::bad_alloc。
[編輯] 注意
與 append() 或 operator/= 不同,永遠不會引入額外的目錄分隔符。
[編輯] 示例
執行此程式碼
#include <experimental/filesystem> #include <iostream> namespace fs = std::experimental::filesystem; int main() { fs::path p1; // empty path p1 += "var"; // does not insert a separator std::cout << "\"\" + \"var\" == " << p1 << '\n'; p1 += "lib"; // does not insert a separator std::cout << "\"\" + \"var\" + \"lib\" == " << p1 << '\n'; }
輸出
"" + "var" == "var" "" + "var" + "lib" == "varlib"
[編輯] 參閱
向路徑追加元素 (public member function) | |
用目錄分隔符連線兩個路徑 (function) |