wcstoll() function in C/C++

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 :

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate
// the function wcstoll()
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    // wide-character type array string starting
    // with integral 'L'
    wchar_t string1[] = L"888geekforgeeks";
    wchar_t string2[] = L"999gfg";
  
    // End pointer will point to the characters
    // after integer, according to the base
    wchar_t* End;
  
    // Initializing base
    int b = 10; 
    int value;
  
    value = wcstoll(string1, &End, b);
    value = wcstoll(string2, &End, b);
  
    // prints the whole input string
    wcout << "String Value = " << string1 << "\n";
    wcout << "Long Long Int value = " << value << "\n";
  
    // prints the end string after the integer
    wcout << "End String = " << End << "\n";
  
    wcout << "String Value = " << string2 << "\n";
    wcout << "Long Long Int Value = " << value << "\n";
    wcout << "End String = " << End << "\n";
    return 0;
}

chevron_right


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

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the function wcstoll()
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    // End pointer, will point to the characters
    // after integer, according to the base
    wchar_t* End;
  
    // wide-character type array string
    wchar_t string[] = L"1356geekforgeeks";
  
    // Prints the long long integer provided with base 5
    wcout << "Long Long Int with base5 = "
    << wcstoll(string, &End, 5) << "\n";
  
    wcout << "End String = " << End << "\n";
  
    // Prints the long long integer provided with base 12
    wcout << "Long Long Int with base12 = " 
    << wcstoll(string, &End, 12) << "\n";
  
    wcout << "End String = " << End << "\n";
  
    // Prints the long long integer provided with base 36
    wcout << "Long Long Int with base36 = "
    << wcstoll(string, &End, 36) << "\n";
  
    wcout << "End String = " << End << "\n";
  
    return 0;
}

chevron_right


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 =


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.