Name
mbrtowc function — Converts a multibyte character to a wide character
Synopsis
size_t mbrtowc(wchar_t* pwc, const char* str, size_t n, mbstate_t* ps)
The mbrtowc
function
converts a multibyte character to a wide character. First, it counts
the number of bytes needed to complete the next multibyte character
that str
points to. At most,
n
bytes of str
are examined. If str
points to a valid multibyte character,
that character is converted to a wide character, which is stored in
*pwc
.
The ps
parameter points to
the shift state, which keeps track of the conversion state between
calls to mbrtowc
. If ps
is a null pointer, an internal shift
state is used (which is similar to calling mbtowc
in <cstdlib>
).
The return value is one of the following:
0
If the multibyte character represents the null wide character
static_cast<size_t>(-1)
If
str
does not point to a valid multibyte characterstatic_cast<size_t>(-2)
If
n
is too small- Anything else
If the multibyte character is valid, in which case the value returned is the number of bytes in the multibyte character
See Also
mbstate_t type,
mbtowc
in <cstdlib>
, codecvt
in <locale>
Get C++ In a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.