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。
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP