std::experimental::filesystem::path:: path
From cppreference.net
<
cpp
|
experimental
|
fs
|
path
|
path
(
)
;
|
(1) | (文件系统 TS) |
|
path
(
const
path
&
p
)
;
|
(2) | (文件系统 TS) |
|
path
(
path
&&
p
)
;
|
(3) | (文件系统 TS) |
|
template
<
class
Source
>
path ( const Source & source ) ; |
(4) | (文件系统 TS) |
|
template
<
class
InputIt
>
path ( InputIt first, InputIt last ) ; |
(5) | (文件系统 TS) |
|
template
<
class
Source
>
path ( const Source & source, const std:: locale & loc ) ; |
(6) | (文件系统 TS) |
|
template
<
class
InputIt
>
path ( InputIt first, InputIt last, const std:: locale & loc ) ; |
(7) | (文件系统 TS) |
构造一个新的
path
对象。
1)
构造一个空路径。
2)
复制构造函数。构造
p
的副本。
3)
移动构造函数。构造
p
的副本,
p
将处于有效但未指定的状态。
4,5)
从字符序列构造路径,该序列由
source
(4)
提供——可以是指向空终止字符/宽字符序列的指针或输入迭代器,也可以是
std::basic_string
,或以输入迭代器对 [
first
,
last
)
(5)
的形式表示。允许使用四种字符类型
char
、
char16_t
、
char32_t
、
wchar_t
中的任意一种,转换到本机字符集的方法取决于
source
使用的字符类型。
-
- 若源字符类型为 char ,则假定源编码为本机窄字符编码(因此在 POSIX 系统上不发生转换)。
- 若源字符类型为 char16_t ,则使用从 UTF-16 到本机文件系统编码的转换。
- 若源字符类型为 char32_t ,则使用从 UTF-32 到本机文件系统编码的转换。
- 若源字符类型为 wchar_t ,则假定输入为本机宽字符编码(因此在 Windows 系统上不发生转换)。
6,7)
从字符序列构造路径,该序列由
source
(6)
提供(可以是指向空终止字符序列的指针或输入迭代器,或者是
std::string
),或以输入迭代器对 [
first
,
last
) 的形式表示
(7)
。允许的唯一字符类型是
char
。使用
loc
执行字符编码转换。如果
value_type
是
wchar_t
,则使用
std::
codecvt
<
wchar_t
,
char
,
std::
mbstate_t
>
转换面进行到宽字符的转换。否则,首先使用
std::
codecvt
<
wchar_t
,
char
,
std::
mbstate_t
>
转换面转换为宽字符,然后使用
std::
codecvt
<
wchar_t
, value_type
>
转换面从宽字符转换为文件系统原生字符类型。
目录 |
参数
| p | - | 要复制的路径 |
| source | - | 可以是 std::basic_string 、指向以空字符结尾的字符串的指针,或指向以空字符结尾的字符序列的输入迭代器(对于重载 (6) ,字符类型必须为 char ) |
| first, last | - | 指定UTF-8编码字符序列的 LegacyInputIterator s 迭代器对 |
| loc | - | 定义要使用的编码转换的区域设置 |
| 类型要求 | ||
-
InputIt
必须满足
LegacyInputIterator
的要求。
|
||
-
InputIt
的值类型必须是四种字符类型
char
、
wchar_t
、
char16_t
和
char32_t
之一,才能使用重载
(5)
。
|
||
-
InputIt
的值类型必须是
char
,才能使用重载
(7)
。
|
||
异常
1,2)
(无)
3)
noexcept
规范:
noexcept
4-7)
(无)
注释
关于从Unicode字符串生成可移植路径名的说明,请参阅 u8path 。
示例
运行此代码
#include <experimental/filesystem> #include <iostream> namespace fs = std::experimental::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"
参见
从 UTF-8 编码源创建
path
对象
(函数) |