C Standard Libraries C++

mblen()

Declaration

int mblen(const char* kcpMultibyteChar, size_t qMaxCount);

Description

This function returns the length of a multibyte character. Here, "kcpMultibyteChar" is a pointer to a mutlibyte-character sequence and "qMaxCount" is the maximum number of bytes to check.

Example

#include <iostream>
#include <cstdlib>

int main() {
    using namespace std;

    char* cpMultibyteChar       = new char[MB_CUR_MAX + 1];
    wchar_t wWideChar           = L'X';

    int iMultbyteChars          = wctomb(cpMultibyteChar, wWideChar);
    int iLength                 = mblen(cpMultibyteChar, MB_CUR_MAX);
    // Add null-terminator
    cpMultibyteChar[iLength]    = 0;

    cout << cpMultibyteChar << endl;
    cout << iLength << endl;
    cout << iMultbyteChars << endl;

    delete [] cpMultibyteChar;

    return 0;
}

Output

mblen() Output
 

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