C Standard Libraries C++

mbrlen()

Declaration

size_t mbrlen(const char* kcpMChar, size_t qMaxSize, mbstate_t qMBState);

Description

This function returns the number of bytes remaining in the current multibyte character pointed to by "kcpMChar" up to "qMaxSize" bytes, using "qMBState" as the multibyte shift state. If "qMBState" is NULL, then the internal shift state is used and the call is similar to mblen() in <cstdlib>.

The call can fail for several reasons and will return the following:

0     if "kcpMChar" points to the NULL wide character
-1     if "kcpMChar" does not point to a valid multibyte character
-2     if "qMaxSize" is not large enough to contain the character

Example

#include <iostream>
#include <cwchar>

int main()
{
    using namespace std;
    char* cpName = "XoaX.txt";

    // Get the length to the end of the first character.
    size_t qReturn = mbrlen(cpName, MB_CUR_MAX, NULL);
    // Check whether the call was successful.
    if (qReturn < 0) {
        cout << "Error!" << endl;
    } else {
        cout << "Char length = " << qReturn << endl;
    }
    return 0;
}

Output

mbrlen() Output
 

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