Javatpoint Logo
Javatpoint Logo

mbsinit() Function in C/C++

In this article, you will learn about the mbsinit() function in C++ with its syntax and examples.

What is the mbsinit() function?

In C/C++, the mbsinit() function is found in the header of the Standard C Library. If a multibyte conversion state object is not in its initial state, it can be determined using this function. Multibyte character encodings like Shift-JIS and UTF-8 are commonly linked to the multibyte conversion state object.

Syntax:

This is the mbsinit() function's prototype:

  • ps: A multibyte conversion state object pointer.
  • The function returns non-zero if the multibyte conversion state object that ps points to is in its original state and otherwise it returns zero.
  • Variable-length byte sequences are used in multibyte character encoding to represent characters. The mbsinit() function comes in useful when handling stateful conversions and working with multibyte strings. It facilitates figuring out whether or not a conversion state has been initialized.

Example:

Let us take an example to illustrate the use of the mbsinit() function in C.

Output:

mbsinit() Function in C/C++

Explanation:

In this example, the wide-to-multibyte conversion using the wcrtomb() function is tested both before and after to see if the multibyte conversion state object (state) is in its initial state using mbsinit(). The behavior of multibyte character encoding functions can be impacted by setting the locale to the default locale using the setlocale() function.

Example 2:

Let us take an example to illustrate the use of the mbsinit() function in C++.

Output:

mbsinit() Function in C/C++





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA