The wcstoll() function is used to convert a wide string into a long integer. It sets the pointer to point to the first character after the last character. The syntax is as follows.
long long wcstoll(const wchar_t* str, wchar_t** str_end, int base)
This function requires three parameters. The parameters are as follows -
This function returns the converted long long integer. When the character points to NULL, 0 is returned.
#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 }
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’s look at an example with different base values. The base here is 16. By getting a string in a given base, it will be printed in decimal format.
#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 }
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 contains 5E so its value is decimal 94 and the second string contains 125. This is 293 in decimal.
The above is the detailed content of What is the translation of wcstoll() function in C/C++?. For more information, please follow other related articles on the PHP Chinese website!