C/C++ 中的 wcstoll() 函数
wcstoll() 函数用于将宽字符字符串转换为 long long 整数。它将指针设置为指向最后一个字符之后第一个字符。语法如下。
long long wcstoll(const wchar_t* str, wchar_t** str_end, int base)
此函数采用三个参数。这些参数如下所示 -
- str: 这是宽字符串的开头。
- str_end: str_end 被函数设置为紧随最后一个有效字符的下一个字符(如果存在字符),否则为空。
- base: 这指定了基数。基数值可以为 (0, 2, 3, …, 35, 36)
此函数返回转换后的 long long 整数。当字符指向 NULL 时,它将返回 0。
示例
#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
现在让我们看看具有不同基数值的示例。此处的基数为 16。通过获取给定基数的字符串,它将以十进制格式打印。
示例
#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
此处字符串包含 5E 因此其值为十进制中的 94,第二个字符串包含 125。这是十进制中的 293。
广告