std::experimental::filesystem::path::concat, std::experimental::filesystem::path::operator+=
来自 cppreference.cn
< 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) |