mbrtoc32(): This function is available in the file uchar.h.The multibyte character pointed by pmb is converted to a 32-bit character and stored at the location pointed by pc32. This function returns the length in bytes of the multibyte character (up to the max).
Syntax:
size_t mbrtoc32 ( char32_t * pc32, const char * pmb, size_t max, mbstate_t * ps)
Parameters: Four parameters are required for this function.
pc32:Pointer to an object of type char32_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.
Note: It returns the number of bytes from pmb used to produce the 32-bit character.
Approach
C++
#include <bits/stdc++.h>using namespace std;int main(){mbstate_t ps;char32_t pc32;char s[] = "ABCD";int length = mbrtoc32(&pc32, s, MB_CUR_MAX, &ps);if (length < 0){cout << "Failed\n";}else{cout << length << "\n";cout << pc32 << "\n";}return 0;return 0;}
No comments:
Post a Comment