Javatpoint Logo
Javatpoint Logo

wctob() function in C++

The wctob() function in C++ is used to translate a wide character into an equivalent single-byte character representation. It is a component of the <cwchar> header. It is usually applied to multibyte character encodings.

Syntax:

It has the following syntax:

Parameters:

wc: You wish to convert this wide character of type wint_t.

Return Value:

  • The function returns the corresponding single-byte character representation for a wide character (wc) that can be represented as an unsigned char cast to an int.
  • The function returns EOF if and only if wc is the wide character representation of an invalid single-byte character or WEOF (end-of-file wide character).

Description:

  • The wctob() function is commonly used in the context of multibyte character encodings because not all wide characters can be represented as single-byte characters.
  • It determines if a single-byte character is represented for a given wide character (WCC).
  • If so, an integer representing the single-byte character representation is returned. It returns EOF if it doesn't or if wc is WEOF to indicate an error or end-of-file.

Example 1:

Let's take an example to illustrate the use of the wctob() function in C++.

Output:

wctob() function in C++

Explanation:

  • This example will print the corresponding single-byte character if wideChar is a wide character with a valid single-byte character representation. It will print an error message.
  • Remember that the wctob() function works best when combined with other wide character functions, and that the program's particular locale and encoding settings may affect how the function behaves.

Example 2:

Let's take another example to illustrate the use of the wctob() function in C++.

Output:

wctob() function in C++

Example 3:

Let's take another example to illustrate the use of the wctob() function in C++.

Output:

wctob() function in 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