| Technical Specification | ||||
| Filesystem library(filesystem TS) | ||||
| Library fundamentals(library fundamentals TS) | ||||
| Library fundamentals 2(library fundamentals TS v2) | ||||
| Library fundamentals 3(library fundamentals TS v3) | ||||
| Extensions for parallelism(parallelism TS) | ||||
| Extensions for parallelism 2(parallelism TS v2) | ||||
| Extensions for concurrency(concurrency TS) | ||||
| Extensions for concurrency 2(concurrency TS v2) | ||||
| Concepts(concepts TS) | ||||
| Ranges(ranges TS) | ||||
| Reflection(reflection TS) | ||||
| Mathematical special functions(special functions TR) | ||||
| Experimental Non-TS | ||||
| Pattern Matching | ||||
| Linear Algebra | ||||
| std::execution | ||||
| Contracts | ||||
| 2D Graphics |
| Classes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| File types | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
| Path decomposition | ||||
| Non-member functions | ||||
u8path | ||||
Defined in header <experimental/filesystem> | ||
template<class Source> path u8path(const Source& source); | (1) | (filesystem TS) |
template<class InputIt> path u8path( InputIt first, InputIt last); | (2) | (filesystem TS) |
Constructs a pathp from a UTF-8 encoded sequence ofchars, supplied either as anstd::string, or as a null-terminated multibyte string, or as a [first,last) iterator pair.
path::value_type ischar and native encoding is UTF-8, constructs a path directly as if bypath(source) orpath(first, last). Note: this is the typical situation of a POSIX system that uses Unicode, such as Linux.path::value_type iswchar_t and native encoding is UTF-16 (this is the situation on Windows), or ifpath::value_type ischar16_t (native encoding guaranteed UTF-16) orchar32_t (native encoding guaranteed UTF-32), then first converts the UTF-8 character sequence to a temporary stringtmp of typepath::string_type and then the new path is constructed as if bypath(tmp).tmp of typestd::u32string, and then the new path is constructed as if bypath(tmp) (this path is taken on a POSIX system with a non-Unicode multibyte or single-byte encoded filesystem).Contents |
| source | - | a UTF-8 encodedstd::string, pointer to a null-terminated multibyte string, or an input iterator with char value type that points to a null-terminated multibyte string |
| first, last | - | pair ofLegacyInputIterators that specify a UTF-8 encoded character sequence |
| Type requirements | ||
-InputIt must meet the requirements ofLegacyInputIterator. | ||
-The value type ofInputIt must bechar. | ||
The path constructed from the input string after conversion from UTF-8 to the filesystem's native character encoding.
May throwfilesystem_error on underlying OS API errors orstd::bad_alloc if memory allocation fails.
On systems where native path format differs from the generic path format (neither Windows nor POSIX systems are examples of such OSes), if the argument to this function is using generic format, it will be converted to native.
#include <clocale>#include <cstdio>#include <experimental/filesystem>#include <fstream>#include <iostream>namespace fs= std::experimental::filesystem; int main(){std::setlocale(LC_ALL,"en_US.utf8");std::locale::global(std::locale("en_US.utf8")); fs::path p= fs::u8path(u8"要らない.txt"); // native string representation can be used with OS APIsstd::ofstream(p)<<"File contents";// this uses operator string()if(std::FILE* f=std::fopen(p.c_str(),"r")){int ch;while((ch=fgetc(f))!=EOF) putchar(ch);std::fclose(f);} // multibyte and wide representation can be used for outputstd::cout.imbue(std::locale());std::cout<<"\nFile name in narrow multibyte encoding: "<< p.string()<<'\n'; std::wcerr.imbue(std::locale());std::wcerr<<"File name in wide encoding: "<< p.wstring()<<'\n'; fs::remove(p);}
Possible output:
File contentsFile name in narrow multibyte encoding: 要らない.txtFile name in wide encoding: 要らない.txt
| represents a path (class)[edit] |