Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
Miscellaneous
complex
exception
functional
iterator
limits
locale
memory
new
numeric
stdexcept
typeinfo
utility
valarray
locale
has_facet
isalnum
isalpha
iscntrl
isdigit
isgraph
islower
isprint
ispunct
isspace
isupper
isxdigit
locale
tolower
toupper
use_facet
standard facets:
codecvt
codecvt_base
codecvt_byname
collate
collate_byname
ctype
ctype_base
ctype_byname
messages
messages_base
messages_byname
moneypunct
moneypunct_byname
money_base
money_get
money_put
numpunct
numpunct_byname
num_get
num_put
time_base
time_get
time_get_byname
time_put
time_put_byname
codecvt
codecvt::codecvt
public member functions:
codecvt::always_noconv
codecvt::encoding
codecvt::in
codecvt::length
codecvt::max_length
codecvt::out
codecvt::unshift
public member types:
codecvt::extern_type
codecvt::intern_type
codecvt::result
codecvt::state_type
protected members:
codecvt::do_always_noconv
codecvt::do_encoding
codecvt::do_in
codecvt::do_length
codecvt::do_max_length
codecvt::do_out
codecvt::do_unshift
codecvt::~codecvt


codecvt::encoding

public member function
int encoding() const throw();

Return encoding width

Returns the width of an internal character in terms of external characters, if this is a fixed value.

Otherwise, if this is a variable value, the function returns 0.

Alternatively, if the encoding of an external sequence is state-dependent, the function returns -1.

During its operation, this function simply calls the virtual protected member codecvt::do_encoding, which is the member function in charge of performing the actions described above.

Parameters

none

Return value

One of the following, describing how external characters are encoded:
valueinterpretation
-1Encoding is state-dependent
0Characters have a variable width
other valuesFixed amount of external characters equivalent to one internal character

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// codecvt::encoding example
#include <iostream>
#include <locale>
using namespace std;
int main ()
{
  locale loc;
  const codecvt<wchar_t,char,mbstate_t>& myfacet = 
    use_facet<codecvt<wchar_t,char,mbstate_t> >(loc);
  cout << "Characteristics of codecvt<wchar_t,char,mbstate_t>:" << endl;
  cout << "Encoding: " << myfacet.encoding() << endl;
  cout << "Always noconv: " << myfacet.always_noconv() << endl;
  cout << "Max length: " << myfacet.max_length() << endl;
  return 0;
}


Possible output:

Characteristics of codecvt<wchar_t,char,mbstate_t>:
Encoding: 1
Always noconv: 0
Max length: 5

See also