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如果内存分配失败。
例
二次
#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';
}二次
可能的产出:
二次
"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) | 
 © cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

