Namespaces
Variants
Views
Actions

mbstowcs

From cppreference.com
< c‎ | string‎ | multibyte
Revision as of 13:47, 10 April 2013 by P12 (Talk | contribs)

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <stdlib.h>
</td>

<td></td> <td></td> <tr class="t-dcl ">

<td >
size_t mbstowcs( wchar_t          *dst, const char          *src, size_t len)
</td>

<td class="t-dcl-nopad"> </td> <td > (until C99) </td> </tr> <tr class="t-dcl ">

<td >
size_t mbstowcs( wchar_t *restrict dst, const char *restrict src, size_t len)
</td>

<td class="t-dcl-nopad"> </td> <td > (since C99) </td> </tr> Template:ddcl list end

Converts a multibyte character string from the array whose first element is pointed to by src to its wide character representation. Converted characters are stored in the successive elements of the array pointed to by dst. No more than len wide characters are written to the destination array.

Each character is converted as if by a call to mbtowc, except that the mbtowc conversion state is unaffected. The conversion stops if:

  • The multibyte null character was converted and stored.
  • An invalid (in the current C locale) multibyte character was encountered.
  • The next wide character to be stored would exceed len.

Contents

Notes

In most implementations, this function updates a global static object of type mbstate_t as it processes through the string, and cannot be called simultaneously by two threads, mbsrtowcs should be used in such cases.

POSIX specifies a common extension: if dst is a null pointer, this function returns the number of wide characters that would be written to dst, if converted. Similar behavior is standard for mbsrtowcs.

Parameters

dst - pointer to wide character array where the wide string will be stored
src - pointer to the first element of a null-terminated multibyte string to convert
len - number of wide characters available in the array pointed to by dst

Return value

On success, returns the number of wide characters, excluding the terminating L'\0', written to the destination array.

On conversion error (if invalid multibyte character was encountered), returns (size_t)-1.

Example

See also

Template:c/string/multibyte/dcl list mbsrtowcsTemplate:c/string/multibyte/dcl list wcstombs
C++ documentation for mbstowcs