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、空字符结尾的多字符字符串,或指向空字符结尾的多字符序列的输入迭代器。
6) 与 (4) 相同,除了可能执行字符转换。
7) 与 (5) 相同。
8) 与 (5) 相同,除了该序列由指定多字符字符串的任何迭代器对表示。
目录 |
[编辑] 参数
p | - | 要追加的路径 |
str | - | 要追加的字符串 |
ptr | - | 指向要追加的空字符结尾字符串开头的指针 |
x | - | 要追加的单个字符 |
source | - | std::basic_string、空字符结尾的多字符字符串,或指向空字符结尾的多字符序列的输入迭代器,它表示路径名称(可以是可移植格式或本机格式) |
first, last | - | LegacyInputIterator 对,用于指定表示路径名称的多字符序列 |
类型要求 | ||
-InputIt 必须满足 LegacyInputIterator 的要求。 | ||
-InputIt 的值类型必须是编码字符类型之一(char、wchar_t、char16_t 和 char32_t)。 | ||
-CharT 必须是编码字符类型之一(char、wchar_t、char16_t 和 char32_t)。 |
[编辑] 返回值
*this
[编辑] 异常
在底层操作系统 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) |