Javatpoint Logo
Javatpoint Logo

wcstoimax() and wcstoumax() function in C/C++

The wcstoimax() and wcstoumax() function in C/C++ operate in the same way as the strtoimax() and strtoumax() functions in C++, other than they are used to convert the data of a wide string (wstring) to an integral number of the given base. This function is defined in the header file cinttypes.

Header file:

wcstoimax() method:

wcstoimax() is an abbreviation for "Wide Character String to Maximum Integer". It transforms a wide-character string to a numerical maximum-width signed integer of type intmax_t. It can convert various bases (e.g., decimal, hexadecimal, octal) according to the format of the input text.

Syntax:

It has the following syntax:

Parameters:

npt: The number to be translated into a wide-character string.

endpt: A pointer to wide characters containing the address that represents the function's first incorrect character in the given input string.

bases: The number system's base (for example, 10 for decimal, 16 for hexadecimal, and so on).

Return Value:

The function returns two values, which are as follows:

  • If there is a proper conversion, the function returns the resultant integral number as an integer value.
  • If no proper conversion can be done, a value of zero (0) is returned.

Example:

Output:

Programming in base 36 is 94215099711813100 in base 10

The given input String is = Programming
The Number with the base 30 in the given string 15309807264430906 in base 10
the end of the string points to 

wcstoumax() method:

The wcstoumax() method transforms the wide-character string npt to the integer type uintmax_t. Base input values are 0 and in the range of 2-36. The wcstoumax() function is the same as the wcstoul() and wcstoull() functions. The only distinction is that the returned value corresponds to the type uintmax_t.

Syntax:

It has the following syntax:

Parameters:

npt: The number to be translated into a wide-character string.

endpt: It is a pointer that contains wide characters containing the address that represents the function's first incorrect character in the given input string.

bases: The number system's base (for example, 10 for decimal, 16 for hexadecimal, and so on).

Example:

Output:

The given input String = 123abc
The Value stored in the number is: 123
The end of the string points to abc

The given input String = abcdeed
The Value stored in the number is: 0
The end of the string points to abcdeed

Uses of wcstoimax() and wcstoumax() function:

  • When dealing with maximum-width signed integers in multiple bases, use wcstoimax() to convert wide-character sequences representing numbers to intmax_t type.
  • When dealing with maximum-width unsigned integers in multiple bases, use wcstoumax() to convert wide-character strings denoting integers to uintmax_t type.






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