The wcstoll() function is used to convert the wide character string to long long integers. It sets the pointer to point to the first character after the last one. The syntax is like below.
long long wcstoll(const wchar_t* str, wchar_t** str_end, int base)
This function takes three arguments. These arguments are like below −
- str: This is the starting of a wide string.
- str_end: The str_end is set by the function to the next character, after the last valid character, if there is any character, otherwise null.
- base: This specifies the base. The base values can be of (0, 2, 3, …, 35, 36)
This function returns the converted long long integer. When the character points to NULL, it returns 0.
Example
#include <iostream> using namespace std; main() { //Define two wide character string wchar_t string1[] = L"777HelloWorld"; wchar_t string2[] = L"565Hello"; wchar_t* End; //The end pointer int base = 10; int value; value = wcstoll(string1, &End, base); wcout << "The string Value = " << string1 << "\n"; wcout << "Long Long Int value = " << value << "\n"; wcout << "End String = " << End << "\n"; //remaining string after long long integer value = wcstoll(string2, &End, base); wcout << "\nThe string Value = " << string2 << "\n"; wcout << "Long Long Int value = " << value << "\n"; wcout << "End String = " << End; //remaining string after long long integer }
Output
The string Value = 777HelloWorld Long Long Int value = 777 End String = HelloWorld The string Value = 565Hello Long Long Int value = 565 End String = Hello
Now Let us see the example with a different base value. Here the base is 16. By taking the string of given base, it will print in decimal format.
Example
#include <iostream> using namespace std; main() { //Define two wide character string wchar_t string1[] = L"5EHelloWorld"; wchar_t string2[] = L"125Hello"; wchar_t* End; //The end pointer int base = 16; int value; value = wcstoll(string1, &End, base); wcout << "The string Value = " << string1 << "\n"; wcout << "Long Long Int value = " << value << "\n"; wcout << "End String = " << End << "\n"; //remaining string after long long integer value = wcstoll(string2, &End, base); wcout << "\nThe string Value = " << string2 << "\n"; wcout << "Long Long Int value = " << value << "\n"; wcout << "End String = " << End; //remaining string after long long integer }
Output
The string Value = 5EHelloWorld Long Long Int value = 94 End String = HelloWorld The string Value = 125Hello Long Long Int value = 293 End String = Hello
Here the string is containing 5E so its value is 94 in decimal, and second string is containing 125. This is 293 in decimal.