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

path& operator+=( const path& p );
(1) (C++17 起)
path& operator+=( const string_type& str );
path& operator+=( std::basic_string_view<value_type> str );
(2) (C++17 起)
path& operator+=( const value_type* ptr );
(3) (C++17 起)
path& operator+=( value_type x );
(4) (C++17 起)
template< class Source >
path& operator+=( const Source& source );
(5) (C++17 起)
template< class CharT >
path& operator+=( CharT x );
(6) (C++17 起)
template< class Source >
path& concat( const Source& source );
(7) (C++17 起)
template< class InputIt >
path& concat( InputIterator first, InputIterator last );
(8) (C++17 起)

连接当前路径与参数。

1-7) 附加 path(other).native() 到以原生格式存储于 *this 的路径名。这会直接操纵 native() 的值,并且可能无法在操作系统间移植。
8)return *this += path(first, last)

目录

参数

p - 要附加的路径
str - 要附加的字符串或字符串视图
ptr - 指向要附加的空终止字符串起始的指针
x - 要附加的单个字符
source - std::basic_stringstd::basic_string_view 、空终止多字符字符串或指向空终止多字符序列的输入迭代器,它表示路径名(以可执行或原生格式)
first, last - 一对指定代表路径名的字符序列的输入迭代器 (InputIterator)
类型要求
-
InputIt 必须满足 InputIterator 的要求。
-
InputIt 的 value_type 必须是编码字符类型(charwchar_tchar16_tchar32_t)之一
-
CharT 必须是编码字符类型(charwchar_tchar16_tchar32_t)之一

返回值

*this

异常

若内存分配失败则可能抛出 std::bad_alloc


注意

不同于 append()operator/= ,决不放入附加的分隔符。

示例

#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main() {
    fs::path p1; // 空路径
    p1 += "var"; // 不插入分隔符
    std::cout << "\"\" + \"var\" == " << p1 << '\n';
    p1 += "lib"; // does not insert a separator
    std::cout << "\"\" + \"var\" + \"lib\" == " << p1 << '\n';
}

输出:

"" + "var" == "var"
"" + "var" + "lib" == "varlib"

参阅

添加元素到带目录分隔符的路径
(公开成员函数)
用目录分隔符连接二个路径
(函数)

版本历史

  • (当前 | 先前) 2017年5月1日 (一) 07:14Fruderica讨论 | 贡献. . (2,825字节) (+2,825). . (以“{{cpp/filesystem/path/title|concat|operator+{{=}}}} {{cpp/filesystem/path/navbar}} {{dcl begin}} {{dcl | num=1 | since=c++17 | 1= path& operator+=( const path& p ); ...”为内容创建页面)