path() noexcept;
|
(1) | (C++17 起) |
path( const path& p );
|
(2) | (C++17 起) |
path( path&& p ) noexcept;
|
(3) | (C++17 起) |
path( string_type&& source, format fmt = auto_format );
|
(4) | (C++17 起) |
template< class Source >
path( const Source& source, format fmt = auto_format ); |
(5) | (C++17 起) |
template< class InputIt >
path( InputIt first, InputIt last, format fmt = auto_format ); |
(6) | (C++17 起) |
template< class Source >
path( const Source& source, const std::locale& loc, format fmt = auto_format ); |
(7) | (C++17 起) |
template< class InputIt >
path( InputIt first, InputIt last, const std::locale& loc, format fmt = auto_format ); |
(8) | (C++17 起) |
构造新的 path
对象。
p
相同p
相同, p
留在合法而未指定的状态。source
(4,5) 提供的字符序列构造路径(按 fmt
的指定转译格式),源可以是一个指向空终值字符/宽字符序列的指针或输入迭代器、 std::basic_string 或 std::basic_string_view ,或作为一对输入迭代器 [first
, last
) 提供 (6) 。允许任何四种字符类型 char 、 char16_t 、 char32_t 、 wchar_t ,而且原生字符集的转换方法依赖于 source
所用的字符类型
source
(7) 提供的从字符序列构造路径(按 fmt
的指定转译格式),源可以是指向空终止字符序列的指针或输入迭代器、 std::string 、 std::basic_string_view ,或由一对输入迭代器 [first
, last
) (8) 所代表。仅允许的字符类型是 char 。用 loc
进行字符编码转换。若 value_type
是 wchar_t ,则使用 loc
的 std::codecvt<wchar_t, char, std::mbstate_t> 平面从宽字符转换。否则,首先用 std::codecvt<wchar_t, char, std::mbstate_t> 平面转换到宽字符,再用 loc
的 std::codecvt<wchar_t,value_type> 平面转换到文件系统原生字符类型。目录 |
p | - | 要复制的路径 |
source | - | std::basic_string 、 std::basic_string_view ,指向空终止字符串的指针,或拥有字符 value_type 并指向空终止字符序列的的输入迭代器(对于重载 (7) 字符类型必须是 char ) |
first, last | - | 一对指定 UTF-8 编码字符序列的输入迭代器 (InputIterator )
|
fmt | - | path::format 类型的枚举项,指定路径名格式如何转译 |
loc | - | 定义编码转换所用的本地环境 |
类型要求 | ||
-
InputIt 必须满足 InputIterator 的要求。
|
||
-
InputIt 的 value_type 必须是四种字符类型 char 、 wchar_t 、 char16_t 及 char32_t 之一,以使用重载 (6)
|
||
-
InputIt 的 value_type 必须是 char ,以使用 (8)
|
关于从 Unicode 字符串生成可移植路径名,可见 u8path 。
#include <iostream> #include <filesystem> namespace fs = std::filesystem; int main() { fs::path p1 = "/usr/lib/sendmail.cf"; // 可移植格式 fs::path p2 = "C:\\users\\abcdef\\AppData\\Local\\Temp\\"; // 原生格式 fs::path p3 = L"D:/猫.txt"; // 宽字符串 std::cout << "p1 = " << p1 << '\n' << "p2 = " << p2 << '\n' << "p3 = " << p3 << '\n'; }
输出:
p1 = "/usr/lib/sendmail.cf" p2 = "C:\users\abcdef\AppData\Local\Temp\" p3 = "D:/猫.txt"
(C++17)
|
从 UTF-8 编码源创建 path (函数) |