wcstoll()函数用于将宽字符串转换为长整型。它将指针设置为指向最后一个字符之后的第一个字符。语法如下。
long long wcstoll(const wchar_t* str, wchar_t** str_end, int base)
该函数需要三个参数。这些参数如下所示 -
该函数返回转换后的 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。
以上是在C/C++中,wcstoll()函数的翻译是什么?的详细内容。更多信息请关注PHP中文网其他相关文章!