---
name: "std::codecvt"
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::codecvt"
---

# std::codecvt(3)

Primary class template codecvt.

## NAME

std::codecvt\< \_InternT, \_ExternT, \_StateT \> - Primary class template codecvt.

## SYNOPSIS

\#include \<locale\>

Inherits **std::\_\_codecvt\_abstract\_base\< \_InternT, \_ExternT, \_StateT \>**.

Inherited by **std::codecvt\_byname\< \_InternT, \_ExternT, \_StateT \>**.

### Public Types

typedef \_ExternT **extern\_type**\
 typedef \_InternT **intern\_type**\
 typedef codecvt\_base::result **result**\
 typedef \_StateT **state\_type**\

### Public Member Functions

**codecvt** (\_\_c\_locale \_\_cloc, size\_t \_\_refs=0)\
 **codecvt** (size\_t \_\_refs=0)\
 bool **always\_noconv** () const  throw ()\
 int **encoding** () const  throw ()\
 result **in** (state\_type &\_\_state, const extern\_type \*\_\_from, const extern\_type \*\_\_from\_end, const extern\_type \*&\_\_from\_next, intern\_type \*\_\_to, intern\_type \*\_\_to\_end, intern\_type \*&\_\_to\_next) const\
 Convert from external to internal character set.  int **length** (state\_type &\_\_state, const extern\_type \*\_\_from, const extern\_type \*\_\_end, size\_t \_\_max) const\
 int **max\_length** () const  throw ()\
 result **out** (state\_type &\_\_state, const intern\_type \*\_\_from, const intern\_type \*\_\_from\_end, const intern\_type \*&\_\_from\_next, extern\_type \*\_\_to, extern\_type \*\_\_to\_end, extern\_type \*&\_\_to\_next) const\
 Convert from internal to external character set.  result **unshift** (state\_type &\_\_state, extern\_type \*\_\_to, extern\_type \*\_\_to\_end, extern\_type \*&\_\_to\_next) const\
 Reset conversion state.

### Static Public Attributes

static **locale::id** **id**\

### Protected Member Functions

virtual bool **do\_always\_noconv** () const  throw ()\
 virtual int **do\_encoding** () const  throw ()\
 virtual result **do\_in** (state\_type &\_\_state, const extern\_type \*\_\_from, const extern\_type \*\_\_from\_end, const extern\_type \*&\_\_from\_next, intern\_type \*\_\_to, intern\_type \*\_\_to\_end, intern\_type \*&\_\_to\_next) const\
 virtual int **do\_length** (state\_type &, const extern\_type \*\_\_from, const extern\_type \*\_\_end, size\_t \_\_max) const\
 virtual int **do\_max\_length** () const  throw ()\
 virtual result **do\_out** (state\_type &\_\_state, const intern\_type \*\_\_from, const intern\_type \*\_\_from\_end, const intern\_type \*&\_\_from\_next, extern\_type \*\_\_to, extern\_type \*\_\_to\_end, extern\_type \*&\_\_to\_next) const\
 Convert from internal to external character set.  virtual result **do\_unshift** (state\_type &\_\_state, extern\_type \*\_\_to, extern\_type \*\_\_to\_end, extern\_type \*&\_\_to\_next) const\

### Static Protected Member Functions

static \_\_c\_locale **\_S\_clone\_c\_locale** (\_\_c\_locale &\_\_cloc)  throw ()\
 static void **\_S\_create\_c\_locale** (\_\_c\_locale &\_\_cloc, const char \*\_\_s, \_\_c\_locale \_\_old=0)\
 static void **\_S\_destroy\_c\_locale** (\_\_c\_locale &\_\_cloc)\
 static \_\_c\_locale **\_S\_get\_c\_locale** ()\
 static const char \* **\_S\_get\_c\_name** ()  throw ()\
 static \_\_c\_locale **\_S\_lc\_ctype\_c\_locale** (\_\_c\_locale \_\_cloc, const char \*\_\_s)\

### Protected Attributes

\_\_c\_locale **\_M\_c\_locale\_codecvt**\

## Detailed Description

### template\<typename \_InternT, typename \_ExternT, typename \_StateT\>

class std::codecvt\< \_InternT, \_ExternT, \_StateT \>"Primary class template codecvt.

NB: Generic, mostly useless implementation.

## Member Function Documentation

### template\<typename \_InternT, typename \_ExternT, typename \_StateT\> virtual bool std::codecvt\< \_InternT, \_ExternT, \_StateT \>::do\_always\_noconv () const \[protected\], \[virtual\]

Implements **std::\_\_codecvt\_abstract\_base\< \_InternT, \_ExternT, \_StateT \>**.

### template\<typename \_InternT, typename \_ExternT, typename \_StateT\> virtual int std::codecvt\< \_InternT, \_ExternT, \_StateT \>::do\_encoding () const \[protected\], \[virtual\]

Implements **std::\_\_codecvt\_abstract\_base\< \_InternT, \_ExternT, \_StateT \>**.

### template\<typename \_InternT, typename \_ExternT, typename \_StateT\> virtual result std::codecvt\< \_InternT, \_ExternT, \_StateT \>::do\_in (state\_type & \_\_state, const extern\_type \* \_\_from, const extern\_type \* \_\_from\_end, const extern\_type \*& \_\_from\_next, intern\_type \* \_\_to, intern\_type \* \_\_to\_end, intern\_type \*& \_\_to\_next) const \[protected\], \[virtual\]

Implements **std::\_\_codecvt\_abstract\_base\< \_InternT, \_ExternT, \_StateT \>**.

### template\<typename \_InternT, typename \_ExternT, typename \_StateT\> virtual int std::codecvt\< \_InternT, \_ExternT, \_StateT \>::do\_length (state\_type & , const extern\_type \* \_\_from, const extern\_type \* \_\_end, size\_t \_\_max) const \[protected\], \[virtual\]

Implements **std::\_\_codecvt\_abstract\_base\< \_InternT, \_ExternT, \_StateT \>**.

### template\<typename \_InternT, typename \_ExternT, typename \_StateT\> virtual int std::codecvt\< \_InternT, \_ExternT, \_StateT \>::do\_max\_length () const \[protected\], \[virtual\]

Implements **std::\_\_codecvt\_abstract\_base\< \_InternT, \_ExternT, \_StateT \>**.

### template\<typename \_InternT, typename \_ExternT, typename \_StateT\> virtual result std::codecvt\< \_InternT, \_ExternT, \_StateT \>::do\_out (state\_type & \_\_state, const intern\_type \* \_\_from, const intern\_type \* \_\_from\_end, const intern\_type \*& \_\_from\_next, extern\_type \* \_\_to, extern\_type \* \_\_to\_end, extern\_type \*& \_\_to\_next) const \[protected\], \[virtual\]

Convert from internal to external character set. Converts input string of intern\_type to output string of extern\_type. This function is a hook for derived classes to change the value returned.

**See also**

out for more information.

Implements **std::\_\_codecvt\_abstract\_base\< \_InternT, \_ExternT, \_StateT \>**.

### template\<typename \_InternT, typename \_ExternT, typename \_StateT\> virtual result std::codecvt\< \_InternT, \_ExternT, \_StateT \>::do\_unshift (state\_type & \_\_state, extern\_type \* \_\_to, extern\_type \* \_\_to\_end, extern\_type \*& \_\_to\_next) const \[protected\], \[virtual\]

Implements **std::\_\_codecvt\_abstract\_base\< \_InternT, \_ExternT, \_StateT \>**.

### template\<typename \_InternT, typename \_ExternT, typename \_StateT\> result std::\_\_codecvt\_abstract\_base\< \_InternT, \_ExternT, \_StateT \>::in (state\_type & \_\_state, const extern\_type \* \_\_from, const extern\_type \* \_\_from\_end, const extern\_type \*& \_\_from\_next, intern\_type \* \_\_to, intern\_type \* \_\_to\_end, intern\_type \*& \_\_to\_next) const \[inline\], \[inherited\]

Convert from external to internal character set. Converts input string of extern\_type to output string of intern\_type. This is analogous to mbsrtowcs. It does this by calling codecvt::do\_in.

The source and destination character sets are determined by the facet's locale, internal and external types.

The characters in \[from,from\_end) are converted and written to \[to,to\_end). from\_next and to\_next are set to point to the character following the last successfully converted character, respectively. If the result needed no conversion, from\_next and to\_next are not affected.

The *state* argument should be initialized if the input is at the beginning and carried from a previous call if continuing conversion. There are no guarantees about how *state* is used.

The result returned is a member of codecvt\_base::result. If all the input is converted, returns codecvt\_base::ok. If no conversion is necessary, returns codecvt\_base::noconv. If the input ends early or there is insufficient space in the output, returns codecvt\_base::partial. Otherwise the conversion failed and codecvt\_base::error is returned.

**Parameters**

*\_\_state* Persistent conversion state data. \
 *\_\_from* Start of input. \
 *\_\_from\_end* End of input. \
 *\_\_from\_next* Returns start of unconverted data. \
 *\_\_to* Start of output buffer. \
 *\_\_to\_end* End of output buffer. \
 *\_\_to\_next* Returns start of unused output area.

**Returns**

codecvt\_base::result.

### template\<typename \_InternT, typename \_ExternT, typename \_StateT\> result std::\_\_codecvt\_abstract\_base\< \_InternT, \_ExternT, \_StateT \>::out (state\_type & \_\_state, const intern\_type \* \_\_from, const intern\_type \* \_\_from\_end, const intern\_type \*& \_\_from\_next, extern\_type \* \_\_to, extern\_type \* \_\_to\_end, extern\_type \*& \_\_to\_next) const \[inline\], \[inherited\]

Convert from internal to external character set. Converts input string of intern\_type to output string of extern\_type. This is analogous to wcsrtombs. It does this by calling codecvt::do\_out.

The source and destination character sets are determined by the facet's locale, internal and external types.

The characters in \[from,from\_end) are converted and written to \[to,to\_end). from\_next and to\_next are set to point to the character following the last successfully converted character, respectively. If the result needed no conversion, from\_next and to\_next are not affected.

The *state* argument should be initialized if the input is at the beginning and carried from a previous call if continuing conversion. There are no guarantees about how *state* is used.

The result returned is a member of codecvt\_base::result. If all the input is converted, returns codecvt\_base::ok. If no conversion is necessary, returns codecvt\_base::noconv. If the input ends early or there is insufficient space in the output, returns codecvt\_base::partial. Otherwise the conversion failed and codecvt\_base::error is returned.

**Parameters**

*\_\_state* Persistent conversion state data. \
 *\_\_from* Start of input. \
 *\_\_from\_end* End of input. \
 *\_\_from\_next* Returns start of unconverted data. \
 *\_\_to* Start of output buffer. \
 *\_\_to\_end* End of output buffer. \
 *\_\_to\_next* Returns start of unused output area.

**Returns**

codecvt\_base::result.

References **do\_out()**.

### template\<typename \_InternT, typename \_ExternT, typename \_StateT\> result std::\_\_codecvt\_abstract\_base\< \_InternT, \_ExternT, \_StateT \>::unshift (state\_type & \_\_state, extern\_type \* \_\_to, extern\_type \* \_\_to\_end, extern\_type \*& \_\_to\_next) const \[inline\], \[inherited\]

Reset conversion state. Writes characters to output that would restore *state* to initial conditions. The idea is that if a partial conversion occurs, then the converting the characters written by this function would leave the state in initial conditions, rather than partial conversion state. It does this by calling codecvt::do\_unshift().

For example, if 4 external characters always converted to 1 internal character, and input to in() had 6 external characters with state saved, this function would write two characters to the output and set the state to initialized conditions.

The source and destination character sets are determined by the facet's locale, internal and external types.

The result returned is a member of codecvt\_base::result. If the state could be reset and data written, returns codecvt\_base::ok. If no conversion is necessary, returns codecvt\_base::noconv. If the output has insufficient space, returns codecvt\_base::partial. Otherwise the reset failed and codecvt\_base::error is returned.

**Parameters**

*\_\_state* Persistent conversion state data. \
 *\_\_to* Start of output buffer. \
 *\_\_to\_end* End of output buffer. \
 *\_\_to\_next* Returns start of unused output area.

**Returns**

codecvt\_base::result.

## Author

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