C Standard Libraries C++
wcsrtombs()
Declaration
size_t wcsrtombs(char* cpMBString,
const wchar_t** kwppWideStr,
sizeof uiConvSize,
mbstate_t* qpMBState);
Description
This function takes "uiConvSize" wide-characters of the wide-character string pointed to by the double pointer "kwppWideStr" and converts them to a mult-byte string which is stored in "cpMBString" using the multibyte conversion state given by "qpMBState." The function returns the number of bytes that were successfully converted, not includng a the possible null-terminator. If the conversion was not successful, -1 is returned. Note that if NULL is passed in for "cpMBString" the function returns the required size for the array "cpMBString." If NULL is passed in for "qpMBState," the function uses the internal conversion state.
Example
#include <cwchar>
int main()
{
wchar_t waString[] = L"XoaX.net";
wchar_t wChar = L'X';
wchar_t* wpFound = wcsrchr(waString, wChar);
wprintf(L"Searching \"%ws\" for the character \"%wc\"\n",
waString, wChar);
wprintf(L"Found \"%wc\" at index %d\n",
wpFound[0], (int)(wpFound - waString));
getwchar();
return 0;
}
Output