首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::filesystem::path::append

path& operator/=(const path& p);

(1)

(since C++17)

template< class Source > path& operator/=( const Source& source );

(2)

(since C++17)

template< class Source > path& append( const Source& source );

(3)

(since C++17)

template< class InputIt > path& append( InputIt first, InputIt last );

(4)

(since C++17)

1%29首先,将首选目录分隔符追加到this,除非下列任何条件都是真实的:

%2A分离器将是多余的%28*this已经以分隔符%29结尾

%2A*this为空,或者添加它会以其他方式将相对路径转换为绝对路径。

%2Ap是一条空路。

%2Ap.native()从目录分隔符开始。

然后,追加p.native()维护的路径名。*this

如果p.has_root_name()true...

2,3%29与%281%29相同,但接受任何std::basic_string,,,std::basic_string_view或指向空终止多字符序列的输入迭代器.。相当于return operator/=(path(source));...

4%29与%281%29相同,但接受指定多字符字符串的任何迭代器对。相当于return operator/=(path(first, last));

参数

p

-

pathname to append

source

-

std::basic_string, std::basic_string_view, null-terminated multicharacter string, or an input iterator pointing to a null-terminated multicharacter sequence, which represents a path name (either in portable or in native format)

first, last

-

pair of InputIterators that specify a multicharacter sequence that represents a path name

类型要求

-输入必须符合输入器的要求。

-InputIt的值类型必须是编码字符类型%28 char,wchar[医]T,char16[医]T和char32[医]t%29

返回值

*this...

例外

可抛filesystem_error关于基础OS API错误或std::bad_alloc如果内存分配失败。

二次

代码语言:javascript
复制
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main() {
    fs::path p1 = "C:";
    p1 /= "Users"; // does not insert a separator
    std::cout << "\"C:\" / \"Users\" == " << p1 << '\n';
    p1 /= "batman"; // inserts fs::path::preferred_separator, '\' on Windows
    std::cout << "\"C:\" / \"Users\" / \"batman\" == " << p1 << '\n';
}

二次

可能的产出:

二次

代码语言:javascript
复制
"C:" / "Users" == "C:Users"
"C:" / "Users" / "batman" == "C:Users\batman"

二次

另见

concatoperator+=

concatenates two paths without introducing a directory separator (public member function)

operator/

concatenates two paths with a directory separator (function)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com