C Standard Libraries C++

wctomb()

Declaration

int wctomb(char* cpMultibyteChar, wchar_t wWideChar);

Description

This function converts a wide character to to a multibyte character. The argument "cpMultibyteChar" is a pointer to a multibyte char and "wWideChar" is a wide character. The function returns the number of bytes converted.

Example

#include <cstdlib>
#include <cstdio>

int main() {
    wchar_t wWideChar       = L'X';
    char* cpMultibyteChar   = new char[2*MB_CUR_MAX];

    // Convert to a multibyte char
    int iConvertLength      = wctomb(cpMultibyteChar, wWideChar);
    // Null terminate the chars
    cpMultibyteChar[iConvertLength] = 0;
    printf("Conversion Length = %d\n", iConvertLength);
    printf("Conversion = %s\n", cpMultibyteChar);

    delete [] cpMultibyteChar;
    // Keep the window open until "Enter" is pressed
    getchar();
    return 0;
}

Output

wctomb() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.