C Standard Libraries C++

mbsrtowcs()

Declaration

size_t mbsrtowcs(wchar_t* wpConverted,
                const char** kcppMString,
                size_t qCharCount,
                mbstate_t qMBState);

Description

This function converts the multibyte character string that "kcppMString" points to into the wide character string "wpConverted". The function converts up to "qCharCount" characters, using "qMBState" as the multibyte shift state. If "qMBState" is NULL, then the internal shift state is used. The function returns the number of characters converted or -1 if an error occured.

Example

#include <iostream>
#include <cwchar>

int main()
{
    using namespace std;
    const char* kcpName = "XoaX.txt";
    wchar_t waWideString[10];

    // Convert the string kcpName
    size_t qReturn = mbsrtowcs(waWideString, &kcpName, 9, NULL);
    // Check whether the call was successful.
    if (qReturn < 0) {
        cout << "Error!" << endl;
    } else {
        cout << "Conversion length = " << qReturn << endl;
        wcout << "Converted wide string = " << waWideString << endl;
    }
    return 0;
}

Output

mbsrtowcs() Output
 

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