命名空间
变体
操作

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

来自 cppreference.cn
< cpp‎ | experimental‎ | fs‎ | path
 
 
实验性
技术规范
文件系统库 (filesystem TS)
库基础 (library fundamentals TS)
库基础 2 (library fundamentals TS v2)
库基础 3 (library fundamentals TS v3)
并行扩展 (parallelism TS)
并行扩展 2 (parallelism TS v2)
并发扩展 (concurrency TS)
并发扩展 2 (concurrency TS v2)
概念 (concepts TS)
范围 (ranges TS)
反射 (reflection TS)
数学特殊函数 (special functions 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 指向的首字符的空字符结尾字符串的连接。
4)(1) 相同,除了结果的 native() 是原始 native() 和单个字符 x 的连接。
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 的值类型必须是编码字符类型之一(charwchar_tchar16_tchar32_t)。
-
CharT 必须是编码字符类型之一(charwchar_tchar16_tchar32_t)。

[编辑] 返回值

*this

[编辑] 异常

在底层操作系统 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) [编辑]