---
name: "std::wstring_convert"
section: "3"
platform: "linux"
package: "gcc"
version: "16.2.1+r23+gd564253eb6c8-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/std::wstring_convert"
---

# std::wstring\_convert(3)

String conversions.

## NAME

std::wstring\_convert\< \_Codecvt, \_Elem, \_Wide\_alloc, \_Byte\_alloc \> - String conversions.

## SYNOPSIS

\#include \<locale\>

### Public Types

typedef **basic\_string**\< char, **char\_traits**\< char \>, \_Byte\_alloc \> **byte\_string**\
 typedef wide\_string::traits\_type::int\_type **int\_type**\
 typedef \_Codecvt::state\_type **state\_type**\
 typedef **basic\_string**\< \_Elem, **char\_traits**\< \_Elem \>, \_Wide\_alloc \> **wide\_string**\

### Public Member Functions

**wstring\_convert** ()\
 Default constructor.  **wstring\_convert** (\_Codecvt \*\_\_pcvt)\
 **wstring\_convert** (\_Codecvt \*\_\_pcvt, state\_type \_\_state)\
 **wstring\_convert** (const byte\_string &\_\_byte\_err, const wide\_string &\_\_wide\_err=wide\_string())\
 **wstring\_convert** (const wstring\_convert &)=delete\
 size\_t **converted** () const noexcept\
 The number of elements successfully converted in the last conversion.  **wstring\_convert** & **operator=** (const **wstring\_convert** &)=delete\
 state\_type **state** () const\
 The final conversion state of the last conversion.

wide\_string **from\_bytes** (char \_\_byte)\
 Convert from bytes.  wide\_string **from\_bytes** (const char \*\_\_ptr)\
 Convert from bytes.  wide\_string **from\_bytes** (const byte\_string &\_\_str)\
 Convert from bytes.  wide\_string **from\_bytes** (const char \*\_\_first, const char \*\_\_last)\
 Convert from bytes.

byte\_string **to\_bytes** (\_Elem \_\_wchar)\
 Convert to bytes.  byte\_string **to\_bytes** (const \_Elem \*\_\_ptr)\
 Convert to bytes.  byte\_string **to\_bytes** (const wide\_string &\_\_wstr)\
 Convert to bytes.  byte\_string **to\_bytes** (const \_Elem \*\_\_first, const \_Elem \*\_\_last)\
 Convert to bytes.

## Detailed Description

### template\<typename \_Codecvt, typename \_Elem = wchar\_t, typename \_Wide\_alloc = allocator\<\_Elem\>, typename \_Byte\_alloc = allocator\<char\>\>

class std::wstring\_convert\< \_Codecvt, \_Elem, \_Wide\_alloc, \_Byte\_alloc \>"String conversions.

## Constructor & Destructor Documentation

### template\<typename \_Codecvt, typename \_Elem = wchar\_t, typename \_Wide\_alloc = allocator\<\_Elem\>, typename \_Byte\_alloc = allocator\<char\>\> std::wstring\_convert\< \_Codecvt, \_Elem, \_Wide\_alloc, \_Byte\_alloc \>::wstring\_convert () \[inline\]

Default constructor.

### template\<typename \_Codecvt, typename \_Elem = wchar\_t, typename \_Wide\_alloc = allocator\<\_Elem\>, typename \_Byte\_alloc = allocator\<char\>\> std::wstring\_convert\< \_Codecvt, \_Elem, \_Wide\_alloc, \_Byte\_alloc \>::wstring\_convert (\_Codecvt \* \_\_pcvt) \[inline\], \[explicit\]

Constructor.

**Parameters**

*\_\_pcvt* The facet to use for conversions.

Takes ownership of \_\_pcvt and will delete it in the destructor.

### template\<typename \_Codecvt, typename \_Elem = wchar\_t, typename \_Wide\_alloc = allocator\<\_Elem\>, typename \_Byte\_alloc = allocator\<char\>\> std::wstring\_convert\< \_Codecvt, \_Elem, \_Wide\_alloc, \_Byte\_alloc \>::wstring\_convert (\_Codecvt \* \_\_pcvt, state\_type \_\_state) \[inline\]

Construct with an initial converstion state.

**Parameters**

*\_\_pcvt* The facet to use for conversions. \
 *\_\_state* Initial conversion state.

Takes ownership of \_\_pcvt and will delete it in the destructor. The object's conversion state will persist between conversions.

### template\<typename \_Codecvt, typename \_Elem = wchar\_t, typename \_Wide\_alloc = allocator\<\_Elem\>, typename \_Byte\_alloc = allocator\<char\>\> std::wstring\_convert\< \_Codecvt, \_Elem, \_Wide\_alloc, \_Byte\_alloc \>::wstring\_convert (const byte\_string & \_\_byte\_err, const wide\_string & \_\_wide\_err = wide\_string()) \[inline\], \[explicit\]

Construct with error strings.

**Parameters**

*\_\_byte\_err* A string to return on failed conversions. \
 *\_\_wide\_err* A wide string to return on failed conversions.

## Member Function Documentation

### template\<typename \_Codecvt, typename \_Elem = wchar\_t, typename \_Wide\_alloc = allocator\<\_Elem\>, typename \_Byte\_alloc = allocator\<char\>\> size\_t std::wstring\_convert\< \_Codecvt, \_Elem, \_Wide\_alloc, \_Byte\_alloc \>::converted () const \[inline\], \[noexcept\]

The number of elements successfully converted in the last conversion.

### template\<typename \_Codecvt, typename \_Elem = wchar\_t, typename \_Wide\_alloc = allocator\<\_Elem\>, typename \_Byte\_alloc = allocator\<char\>\> wide\_string std::wstring\_convert\< \_Codecvt, \_Elem, \_Wide\_alloc, \_Byte\_alloc \>::from\_bytes (char \_\_byte) \[inline\]

Convert from bytes.

References **from\_bytes()**.

Referenced by **from\_bytes()**, **from\_bytes()**, and **from\_bytes()**.

### template\<typename \_Codecvt, typename \_Elem = wchar\_t, typename \_Wide\_alloc = allocator\<\_Elem\>, typename \_Byte\_alloc = allocator\<char\>\> wide\_string std::wstring\_convert\< \_Codecvt, \_Elem, \_Wide\_alloc, \_Byte\_alloc \>::from\_bytes (const byte\_string & \_\_str) \[inline\]

Convert from bytes.

References **std::basic\_string\< \_CharT, \_Traits, \_Alloc \>::data()**, **from\_bytes()**, and **std::basic\_string\< \_CharT, \_Traits, \_Alloc \>::size()**.

### template\<typename \_Codecvt, typename \_Elem = wchar\_t, typename \_Wide\_alloc = allocator\<\_Elem\>, typename \_Byte\_alloc = allocator\<char\>\> wide\_string std::wstring\_convert\< \_Codecvt, \_Elem, \_Wide\_alloc, \_Byte\_alloc \>::from\_bytes (const char \* \_\_first, const char \* \_\_last) \[inline\]

Convert from bytes.

### template\<typename \_Codecvt, typename \_Elem = wchar\_t, typename \_Wide\_alloc = allocator\<\_Elem\>, typename \_Byte\_alloc = allocator\<char\>\> wide\_string std::wstring\_convert\< \_Codecvt, \_Elem, \_Wide\_alloc, \_Byte\_alloc \>::from\_bytes (const char \* \_\_ptr) \[inline\]

Convert from bytes.

References **from\_bytes()**.

### template\<typename \_Codecvt, typename \_Elem = wchar\_t, typename \_Wide\_alloc = allocator\<\_Elem\>, typename \_Byte\_alloc = allocator\<char\>\> state\_type std::wstring\_convert\< \_Codecvt, \_Elem, \_Wide\_alloc, \_Byte\_alloc \>::state () const \[inline\]

The final conversion state of the last conversion.

### template\<typename \_Codecvt, typename \_Elem = wchar\_t, typename \_Wide\_alloc = allocator\<\_Elem\>, typename \_Byte\_alloc = allocator\<char\>\> byte\_string std::wstring\_convert\< \_Codecvt, \_Elem, \_Wide\_alloc, \_Byte\_alloc \>::to\_bytes (\_Elem \_\_wchar) \[inline\]

Convert to bytes.

References **to\_bytes()**.

Referenced by **to\_bytes()**, **to\_bytes()**, and **to\_bytes()**.

### template\<typename \_Codecvt, typename \_Elem = wchar\_t, typename \_Wide\_alloc = allocator\<\_Elem\>, typename \_Byte\_alloc = allocator\<char\>\> byte\_string std::wstring\_convert\< \_Codecvt, \_Elem, \_Wide\_alloc, \_Byte\_alloc \>::to\_bytes (const \_Elem \* \_\_first, const \_Elem \* \_\_last) \[inline\]

Convert to bytes.

### template\<typename \_Codecvt, typename \_Elem = wchar\_t, typename \_Wide\_alloc = allocator\<\_Elem\>, typename \_Byte\_alloc = allocator\<char\>\> byte\_string std::wstring\_convert\< \_Codecvt, \_Elem, \_Wide\_alloc, \_Byte\_alloc \>::to\_bytes (const \_Elem \* \_\_ptr) \[inline\]

Convert to bytes.

References **std::basic\_string\< \_Elem, char\_traits\< \_Elem \>, \_Wide\_alloc \>::length()**, and **to\_bytes()**.

### template\<typename \_Codecvt, typename \_Elem = wchar\_t, typename \_Wide\_alloc = allocator\<\_Elem\>, typename \_Byte\_alloc = allocator\<char\>\> byte\_string std::wstring\_convert\< \_Codecvt, \_Elem, \_Wide\_alloc, \_Byte\_alloc \>::to\_bytes (const wide\_string & \_\_wstr) \[inline\]

Convert to bytes.

References **std::basic\_string\< \_CharT, \_Traits, \_Alloc \>::data()**, **std::basic\_string\< \_CharT, \_Traits, \_Alloc \>::size()**, and **to\_bytes()**.

## Author

Generated automatically by Doxygen for libstdc++ from the source code.
