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::out

public member function
result out ( stateT& state, 
  const internT* from, const internT* from_end, const internT*& from_next,
        externT* to, externT* to_limit, externT*& to_next ) const;

Translate out characters

Translates sequentially the characters in the range [from,from_end) and places them in the range starting at to. It does not attempt to store more characters once to_limit is reached.

When the function returns, from_next and to_next point to one beyond the last element successfully converted.

The translation stops if a character cannot be translated, in which case it returns codecvt::error.

If the destination range cannot absorb all the characters to be translated, or if the generation of a new translated character requires more characters beyond from_end, it returns codecvt::partial.

If both template parameters internT and externT are the same type, the function simply copies the contents and returns codecvt::noconv.

On success, it returns codecvt::ok.

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

Parameters

state
State object to keep track of the state of a multibyte character conversion. Typically, this is an object of type mbstate_t.
stateT is the state type (i.e., the third template parameter of codecvt).
from, from_end
Pointer to the initial and final characters of the source sequence. The range used is [from,from_end), which contains all the characters between from and from_end, including the character pointed by from but not the character pointed by from_end.
internT is the internal character type (i.e., the first template parameter of codecvt).
from_next
Pointer type able to point to an element in the above range. Once the function returns, this object points to the element in the source range beyond the last one successfully translated.
to, to_limit
Pointer to the initial and final characters of the destination sequence. The range used is [to,to_limit), which contains all the characters between to and to_limit, including the character pointed by to but not the character pointed by to_limit.
A translation does not necessarily need to fill up the range to its limit, and may also exhaust it (in which case it returns codecvt::partial).
externT is the external character type (i.e., the second template parameter of codecvt).
to_next
Pointer type able to point to an element in the above range. Once the function returns, this object points to the element in the destination range beyond the last one successfully translated.

Return value

An object of type codecvt::result, with the following possible values:
valueresult
okConversion completed
partialNot all source characters converted
errorA character in the source could not be converted
noconvSource and destination character types are the same. No conversion technique used.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// codecvt::out example
#include <iostream>
#include <locale>
#include <string>
using namespace std;
int main ()
{
  locale mylocale;
  mbstate_t mystate;
  wstring mywstring;
  const codecvt<wchar_t,char,mbstate_t>& myfacet = 
    use_facet<codecvt<wchar_t,char,mbstate_t> >(mylocale);
  codecvt<wchar_t,char,mbstate_t>::result myresult;
  cout << "Enter sentence: ";
  getline (wcin,mywstring);
  size_t length = mywstring.length();
  char* pstr= new char [length+1];
  const wchar_t* pwc;
  char* pc;
  // translate characters:
  myresult = myfacet.out (mystate,
      mywstring.c_str(), mywstring.c_str()+length+1, pwc,
      pstr, pstr+length+1, pc);
  if ( myresult == codecvt<wchar_t,char,mbstate_t>::ok )
	  cout << "Translation successful: " << pstr << endl;
  return 0;
}


Output:

Enter sentence: Test sentence
Translation successful: Test sentence

See also