Home  >  Article  >  Backend Development  >  What is the translation of wcstoll() function in C/C++?

What is the translation of wcstoll() function in C/C++?

王林
王林forward
2023-09-15 17:17:02916browse

What is the translation of wcstoll() function in C/C++?

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 -

  • #str: This is the beginning of a wide string.
  • str_end: The function sets str_end to the next character after the last valid character (if there is any character), otherwise to null.
  • base: This specifies the base. The base value can be (0, 2, 3, …, 35, 36)

This function returns the converted long long integer. When the character points to NULL, 0 is returned.

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’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.

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 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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete