mbrtoc16() in C++

mbrtoc16(): This function is available in the file uchar.h. The multibyte character pointed by pmb is converted to a 16-bit character and stored at the location pointed by pc16. The function returns the length in bytes of the multibyte character (up to the max). This function returns the number of bytes from pmb used to produce the 16-bit character.

Syntax:

size_t mbrtoc16 ( char16_t * pc16, const char * pmb, size_t max, mbstate_t * ps)

Parameters: Four parameters are required for this function.

pc16:Pointer to an object of type char16_t.

pmb: Pointer to the first byte of a multibyte character.

max: Maximum number of bytes to read from pmb. The macro constant MB_CUR_MAX defines the maximum number of bytes that can form a multibyte character under the current locale settings. 

ps: Pointer to a mbstate_t object that defines a conversion state.

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{

    mbstate_t ps;
    char16_t pc16;
    char s[] = "ABCD";
    int length = mbrtoc16(&pc16sMB_CUR_MAX, &ps);

    if (length < 0)
    {
        cout << "Error\n";
    }
    else
    {
        cout << length << "\n";
    }
    return 0;
}


No comments:

Post a Comment