命名空间
变体
操作

std::experimental::filesystem::path::concat, std::experimental::filesystem::path::operator+=

来自 cppreference.cn
< 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)
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)

连接当前路径和参数。

1) 连接 *thisp,使得结果的 native() 恰好是原始 native() 连接 p.native()
2)(1),但结果的 native() 是原始 native() 和字符串 str 的连接。
3)(1),但结果的 native() 是原始 native() 和由 ptr 指向的以 null 结尾字符串的连接。
4)(1),但结果的 native() 是原始 native() 和单个字符 x 的连接。
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 的值类型必须是编码字符类型之一(charwchar_tchar16_tchar32_t)。
-
CharT 必须是编码字符类型之一(charwchar_tchar16_tchar32_t)。

[编辑] 返回值

*this

[编辑] 异常

如果底层 OS API 错误或内存分配失败,可能会抛出 filesystem_errorstd::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) [编辑]