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中文網其他相關文章!