C++ Locale Library - encoding



Description

It 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.

Declaration

Following is the declaration for std::ctype::encoding.

C++98

 int encoding() const throw(); 

C++11

 int encoding() const throw(); 

Parameters

none

Return Value

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

Exceptions

No-throw guarantee − never throws exceptions.

Data races

The facet object is accessed.

Example

In below example explains about std::ctype::encoding.

 #include <iostream> #include <locale> int main () { std::locale loc; const std::codecvt<wchar_t,char,mbstate_t>& myfacet = std::use_facet<std::codecvt<wchar_t,char,mbstate_t> >(loc); std::cout << "Characteristics of codecvt<wchar_t,char,mbstate_t>:\n"; std::cout << "Encoding: " << myfacet.encoding() << '\n'; std::cout << "Always noconv: " << myfacet.always_noconv() << '\n'; std::cout << "Max length: " << myfacet.max_length() << '\n'; return 0; } 

Let us compile and run the above program, this will produce the following result −

 Characteristics of codecvt<wchar_t,char,mbstate_t>: Encoding: 1 Always noconv: 0 Max length: 1 
locale.htm
Advertisements