Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::experi...stem::u8path(3) C++ Standard Libarystd::experi...stem::u8path(3)

NAME
       std::experimental::filesystem::u8path   -   std::experimental::filesys-
       tem::u8path

Synopsis
	  Defined in header <experimental/filesystem>
	  template< class Source >		      (1) (filesystem TS)
	  path u8path( const Source& source );
	  template< class InputIt >		      (2) (filesystem TS)
	  path u8path( InputIt first, InputIt last );

	  Constructs a path p from a UTF-8 encoded sequence of chars, supplied
       either as an
	  std::string, or as a	null-terminated	 multibyte  string,  or	 as  a
       [first, last)
	  iterator pair.

	    *  If  path::value_type is char and	native encoding	is UTF-8, con-
       structs a path
	      directly as if by	path(source) or	path(first, last). Note:  this
       is the typical
	      situation	of a POSIX system that uses Unicode, such as Linux.
	    * Otherwise, if path::value_type is	wchar_t	and native encoding is
       UTF-16 (this is
	      the  situation  on  Windows), or if path::value_type is char16_t
       (native encoding
	      guaranteed  UTF-16)  or  char32_t	 (native  encoding  guaranteed
       UTF-32),	then first
	      converts	the UTF-8 character sequence to	a temporary string tmp
       of type
	      path::string_type	and then the new path is constructed as	if  by
       path(tmp).
	    * Otherwise	(for non-UTF-8 narrow character	encodings and for non-
       UTF-16 wchar_t),
	      first  converts  the  UTF-8  character  sequence	to a temporary
       UTF-32-encoded string
	      tmp of type std::u32string, and then the new path	is constructed
       as if by
	      path(tmp)	(this path is taken on a POSIX system with a  non-Uni-
       code multibyte or
	      single-byte encoded filesystem).

Parameters
			a  UTF-8 encoded std::string, pointer to a null-termi-
       nated multibyte
	  source      -	string,	or an input iterator with char value type that
       points to a
			null-terminated	multibyte string
	  first, last -	pair of	LegacyInputIterators that specify a UTF-8  en-
       coded character
			sequence

Type requirements
	  -
	  InputIt must meet the	requirements of	LegacyInputIterator.
	  -
	  The value type of InputIt must be char.

Return value
	  The  path  constructed  from	the input string after conversion from
       UTF-8 to	the
	  filesystem's native character	encoding.

Exceptions
	  May  throw  filesystem_error	on  underlying	OS   API   errors   or
       std::bad_alloc if memory
	  allocation fails.

Notes
	  On  systems  where  native path format differs from the generic path
       format (neither
	  Windows nor POSIX systems are	examples of such OSes),	if  the	 argu-
       ment to this
	  function is using generic format, it will be converted to native.

Example
       // Run this code

	#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	APIs
	    std::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 output
	    std::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 contents
	File name in narrow multibyte encoding:	.txt
	File name in wide encoding: .txt

See also
	  path represents a path
	       (class)

Category:
	    * Noindexed	pages

http://cppreference.com		  2024.06.10	 std::experi...stem::u8path(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::experimental::filesystem::u8path&sektion=3&manpath=FreeBSD+Ports+15.1.quarterly>

home | help