The mbrtoc16() is a built-in function in C/C++ which converts a narrow multibyte character to a 16 bit character representation. It is defined within the uchar.h header file of C++.
ssize_t mbrtoc16( char16_t* pc16, const char* s, size_t n, mbstate_t* ps);
Parameters: The function accepts four mandatory parameter which are described below:
- s : specifies to the multibyte character to convert.
- pc16 : specifies to the memory location to store the resulting 16 bit character.
- n : specifies the maximum number of bytes in s to convert.
- ps : specifies to an mbstate_t object used when interpreting the multibyte string.
Return Value: The function returns five values as follows:
- 0 if the converted character is a null character.
- the number of bytes (at most n) of the multibyte character that was successfully converted to 16 bit character.
- -3 if the next char16_t from a multi-char16_t character (e.g. a surrogate pair) has now been written to *pc16. No bytes are processed from the input in this case.
- -2 if the next n bytes constitute an incomplete, but so far valid, multibyte character. In this case nothing is written to *pc16.
- -1 if encoding error occurs. In this case nothing is written to *pc16, errno is set to EILSEQ and the value of *ps is unspecified.
Below programs illustrate the above function.
Multibyte string = G Length = 1 16-bit character = 0g71
Multibyte string = Length = 0 16-bit character = 1e0000y
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- cin get() in C++ with Examples
- std::less in C++ with Examples
- Pi(π) in C++ with Examples
- feclearexcept in C++ with Examples
- std::equal_to in C++ with Examples
- std::to_address in C++ with Examples
- cauchy_distribution a() in C++ with Examples
- wmemset() in C/C++ with Examples
- mbrtoc32() in C/C++ with Examples
- std::is_nothrow_copy_constructible in C++ with Examples
- ratio_not_equal() in C++ with examples
- Map of Vectors in C++ STL with Examples
- std::make_signed in C++ with Examples
- std::add_lvalue_reference in C++ with Examples
- std::is_trivially_move_assignable in C++ with Examples
- std::rank in C++ with Examples
- Manipulators in C++ with Examples
- std::bit_xor in C++ with Examples
- SDL library in C/C++ with examples
- ios bad() function in C++ with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.