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

FreeBSD Manual Pages

  
 
  

home | help
std::wbuffe...ffer_convert(3) C++ Standard Libarystd::wbuffe...ffer_convert(3)

NAME
       std::wbuffer_convert::wbuffer_convert	    -	     std::wbuffer_con-
       vert::wbuffer_convert

Synopsis
	  wbuffer_convert() : wbuffer_convert(nullptr) { }	 (1)
	  explicit wbuffer_convert( std::streambuf* bytebuf,

	  Codecvt* pcvt	= new Codecvt,				 (2)

	  state_type state = state_type() );
	  wbuffer_convert(const	std::wbuffer_convert&) =  delete;  (3)	(since
       C++14)

	  1) Default constructor.
	  2) Constructs	the wbuffer_convert object with	the specified underly-
       ing byte	stream,
	  specified codecvt facet, and specified initial conversion state (all
       parameters are
	  optional)
	  3)  The copy constructor is deleted, wbuffer_convert is not CopyCon-
       structible

Parameters
	  bytebuf - pointer to std::streambuf to serve as the underlying  nar-
       row character
		    stream
	  pcvt	   -  pointer  to  a  standalone  (not	managed	 by  a locale)
       std::codecvt facet. The
		    behavior is	undefined if this pointer is null.
	  state	  - the	initial	value of the character conversion state

	 Defect	reports

	  The following	behavior-changing defect reports were applied retroac-
       tively to
	  previously published C++ standards.

	    DR	  Applied to	  Behavior as published	      Correct behavior
	  P0935R0 C++11	     default constructor was explicit made implicit

Example
       // Run this code

	#include <iostream>
	#include <sstream>
	#include <locale>
	#include <codecvt>
	int main()
	{
	    // wrap a UTF-8 string stream in a UCS4 wbuffer_convert
	    std::stringbuf utf8buf(u8"z\u00df\u6c34\U0001f34c");  // or	u8"z"
			       //					    or
       "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9f\x8d\x8c";
	    std::wbuffer_convert<std::codecvt_utf8<wchar_t>>
       conv_in(&utf8buf);
	    std::wistream ucsbuf(&conv_in);
	    std::cout  <<  "Reading  from  a  UTF-8 stringbuf via wbuffer_con-
       vert:\n";
	    for(wchar_t	c; ucsbuf.get(c); )
		std::cout << std::hex << std::showbase << c << '\n';

	    // wrap a UTF-8 aware std::cout in a UCS4 wbuffer_convert to  out-
       put UCS4
	    std::wbuffer_convert<std::codecvt_utf8<wchar_t>>
       conv_out(std::cout.rdbuf());
	    std::wostream out(&conv_out);
	    std::cout  <<  "Sending  UCS4  data	 to std::cout via wbuffer_con-
       vert:\n";
	    out	<< L"z\u00df\u6c34\U0001f34c\n";
	}

Output:
	Reading	from a UTF-8 stringbuf via wbuffer_convert produces
	0x7a
	0xdf
	0x6c34
	0x1f34c
	Sending	UCS4 data to std::cout via wbuffer_convert:
	z

http://cppreference.com		  2022.07.31	 std::wbuffe...ffer_convert(3)

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

home | help