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

std::filesystem::path::path

path();

(1)

(since C++17)

path( const path& p );

(2)

(since C++17)

path( path&& p );

(3)

(since C++17)

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

(4)

(since C++17)

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

(5)

(since C++17)

template< class Source > path( const Source& source, const std::locale& loc );

(6)

(since C++17)

template< class InputIt > path( InputIt first, InputIt last, const std::locale& loc );

(7)

(since C++17)

构造一个新的path对象。

1%29构造空路径。

2%29复制构造函数。构造p...

3%29移动构造函数。构造p,,,p处于有效但未指定的状态。

提供的字符序列构造路径的4-5%29source%284%29,它是指向空结束字符/宽字符序列的指针或输入迭代器,std::basic_string或者std::basic_string_view,或表示为一对输入迭代器。[first,,,last%29%285%29。四种字符类型之一char,,,char16_t,,,char32_t,,,wchar_t,并且转换到本机字符集的方法取决于source

  • 如果源字符类型为char,源的编码被假定为本机窄编码%28,因此在POSIX系统%29上不进行转换。
  • 如果源字符类型为char16_t,使用从UTF-16到本机文件系统编码的转换。
  • 如果源字符类型为char32_t,使用从UTF-32到本机文件系统编码的转换。
  • 如果源字符类型为wchar_t,则假定输入为本机宽编码%28,因此在Windows%29上不进行转换

6-7%29从以下字符序列构造路径:source%286%29,它是指向以空结尾的字符序列的指针或输入迭代器,std::string,一个std::basic_string_view,或表示为一对输入迭代器。[first,,,last%29%28%287%29%29。唯一允许的字符类型是char.用途loc若要执行字符编码转换,请执行以下操作。如果value_typewchar_t,使用std::codecvt<wchar_t, char,std::mbstate_t>loc否则,首先使用std::codecvt<wchar_t, char,std::mbstate_t>方面,然后使用以下方法将其转换为文件系统本机字符类型:std::codecvt<wchar_t,value_type>loc...

参数

p

-

a path to copy

source

-

std::basic_string, std::basic_string_view, pointer to a null-terminated character string, or input iterator with a character value type that points to a null-terminated character sequence (the character type must be char for overload (6)

first, last

-

pair of InputIterators that specify a UTF-8 encoded character sequence

loc

-

locale that defines encoding conversion to use

类型要求

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

-InputIt的值类型必须是char、wchar四种字符类型之一[医]T,char16[医]T和char32[医]t使用重载%285%29%29

-输入值类型必须是字符才能使用重载%287%29%29

例外

1-2%29%280%29

3%29

noexcept规格:

noexcept

4-7%29%280%29

注记

有关从Unicode字符串生成便携路径名的信息,请参见u8路径...

二次

代码语言:javascript
复制
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
    fs::path p1 = "/usr/lib/sendmail.cf"; // portable format
    fs::path p2 = "C:\\users\\abcdef\\AppData\\Local\\Temp\\"; // native format
    fs::path p3 = L"D:/猫.txt"; // wide string
 
    std::cout << "p1 = " << p1 << '\n'
              << "p2 = " << p2 << '\n'
              << "p3 = " << p3 << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
p1 = "/usr/lib/sendmail.cf"
p2 = "C:\users\abcdef\AppData\Local\Temp\"
p3 = "D:/猫.txt"

二次

另见

u8path (C++17)

creates a path from a UTF-8 encoded source (function)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com