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) |
Constructs a new path
object.
p
.p
, p
is left in valid but unspecified state.source
(4), which is a pointer or an input iterator to a null-terminated character/wide character sequence, an std::basic_string
or an std::basic_string_view
, or represented as a pair of input iterators [first
, last
) (5). Any of the four character types char
, char16_t
, char32_t
, wchar_t
is allowed, and the method of conversion to the native character set depends on the character type used by source
char
, the encoding of the source is assumed to be the native narrow encoding (so no conversion takes place on POSIX systems) char16_t
, conversion from UTF-16 to native filesystem encoding is used. char32_t
, conversion from UTF-32 to native filesystem encoding is used. wchar_t
, the input is assumed to be the native wide encoding (so no conversion takes places on Windows)source
(6), which is a pointer or an input iterator to a null-terminated character sequence, an std::string
, an std::basic_string_view
, or represented as a pair of input iterators [first
, last
) ((7)). The only character type allowed is char
. Uses loc
to perform the character encoding conversion. If value_type
is wchar_t
, converts from to wide using the std::codecvt<wchar_t, char, std::mbstate_t>
facet of loc
. Otherwise, first converts to wide using the std::codecvt<wchar_t, char, std::mbstate_t>
facet and then converts to filesystem native character type using std::codecvt<wchar_t,value_type>
facet of 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 InputIterator s that specify a UTF-8 encoded character sequence |
loc | - | locale that defines encoding conversion to use |
Type requirements | ||
-InputIt must meet the requirements of InputIterator . |
||
-The value type of InputIt must be one of the four character types char , wchar_t , char16_t and char32_t to use the overload (5)) |
||
-The value type of InputIt must be char to use the overload (7)) |
noexcept
specification: noexcept
For portable pathname generation from Unicode strings, see u8path.
#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'; }
Output:
p1 = "/usr/lib/sendmail.cf" p2 = "C:\users\abcdef\AppData\Local\Temp\" p3 = "D:/猫.txt"
(C++17) | creates a path from a UTF-8 encoded source (function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/filesystem/path/path