wcstoll() function in C/C++
Last Updated :
21 Aug, 2018
The wcstoll() function in C/C++ converts a wide-character string to a long long integer. It sets the pointer to point the first character after the last character.
Syntax :
long long wcstoll( const wchar_t* str, wchar_t** str_end, int base )
Parameter: The function accepts three mandatory parameters which are described as below:
- str: it specifies a wide string starting with the integral number.
- str_end: the str_end value is set by the function to the next char, after the last valid character, if there any, or it will point to NULL.
- base: specifies the base, the values of Base can be of {0, 2, 3, …, 35, 36}.
Return value: The function returns the converted long long integer. It returns 0, it the character points to NULL.
Below programs illustrate the above function:
Program 1 :
#include <bits/stdc++.h>
using namespace std;
int main()
{
wchar_t string1[] = L "888geekforgeeks" ;
wchar_t string2[] = L "999gfg" ;
wchar_t * End;
int b = 10;
int value;
value = wcstoll(string1, &End, b);
value = wcstoll(string2, &End, b);
wcout << "String Value = " << string1 << "\n" ;
wcout << "Long Long Int value = " << value << "\n" ;
wcout << "End String = " << End << "\n" ;
wcout << "String Value = " << string2 << "\n" ;
wcout << "Long Long Int Value = " << value << "\n" ;
wcout << "End String = " << End << "\n" ;
return 0;
}
|
Output:
String Value = 888geekforgeeks
Long Long Int value = 999
End String = gfg
String Value = 999gfg
Long Long Int Value = 999
End String = gfg
Note: The values for bases can be {0, 2, 3, …, 35, 36}. A set of valid digits for base 2 is {0, 1}, for base 3 is {0, 1, 2} and so on. For bases starting from 11 to 36, valid digits include alphabets. The set of valid digits for base 11 is {0, 1, …, 9, A, a}, for base 12 is {0, 1, …, 9, A, a, B, b} and so on.
Program 2 : function with different bases
#include <bits/stdc++.h>
using namespace std;
int main()
{
wchar_t * End;
wchar_t string[] = L "1356geekforgeeks" ;
wcout << "Long Long Int with base5 = "
<< wcstoll(string, &End, 5) << "\n" ;
wcout << "End String = " << End << "\n" ;
wcout << "Long Long Int with base12 = "
<< wcstoll(string, &End, 12) << "\n" ;
wcout << "End String = " << End << "\n" ;
wcout << "Long Long Int with base36 = "
<< wcstoll(string, &End, 36) << "\n" ;
wcout << "End String = " << End << "\n" ;
return 0;
}
|
Output:
Long Long Int with base5 = 8
End String = 56geekforgeeks
Long Long Int with base12 = 2226
End String = geekforgeeks
Long Long Int with base36 = 9223372036854775807
End String =
Share your thoughts in the comments
Please Login to comment...