C / C++中的wcstoll()函数将宽字符字符串转换为长整型整数。它将指针设置为指向最后一个字符之后的第一个字符。
句法 :
long long wcstoll( const wchar_t* str, wchar_t** str_end, int base )
参数:该函数接受三个强制性参数,如下所述:
- str:它指定一个以整数开头的宽字符串。
- str_end:函数将str_end值设置为最后一个有效字符之后的下一个字符(如果存在),否则它将指向NULL。
- base:指定基数,Base的值可以为{0,2,3,…,35,36}。
返回值:该函数返回转换后的long long整数。它返回0,字符指向NULL。
下面的程序说明了上述函数:
程序1:
// C++ program to illustrate
// the function wcstoll()
#include
using namespace std;
int main()
{
// wide-character type array string starting
// with integral 'L'
wchar_t string1[] = L"888geekforgeeks";
wchar_t string2[] = L"999gfg";
// End pointer will point to the characters
// after integer, according to the base
wchar_t* End;
// Initializing base
int b = 10;
int value;
value = wcstoll(string1, &End, b);
value = wcstoll(string2, &End, b);
// prints the whole input string
wcout << "String Value = " << string1 << "\n";
wcout << "Long Long Int value = " << value << "\n";
// prints the end string after the integer
wcout << "End String = " << End << "\n";
wcout << "String Value = " << string2 << "\n";
wcout << "Long Long Int Value = " << value << "\n";
wcout << "End String = " << End << "\n";
return 0;
}
输出:
String Value = 888geekforgeeks
Long Long Int value = 999
End String = gfg
String Value = 999gfg
Long Long Int Value = 999
End String = gfg
注意:底数的值可以是{0,2,3,…,35,36}。底数2的一组有效数字是{0,1},底数3的一组有效数字是{0,1,2},依此类推。对于从11到36的基数,有效数字包括字母。底数11的有效数字集为{0,1,…,9,A,a},底数12的有效数字为{0,1,…,9,A,a,B,b},依此类推。
程序2:具有不同基础的函数
// C++ program to illustrate the function wcstoll()
#include
using namespace std;
int main()
{
// End pointer, will point to the characters
// after integer, according to the base
wchar_t* End;
// wide-character type array string
wchar_t string[] = L"1356geekforgeeks";
// Prints the long long integer provided with base 5
wcout << "Long Long Int with base5 = "
<< wcstoll(string, &End, 5) << "\n";
wcout << "End String = " << End << "\n";
// Prints the long long integer provided with base 12
wcout << "Long Long Int with base12 = "
<< wcstoll(string, &End, 12) << "\n";
wcout << "End String = " << End << "\n";
// Prints the long long integer provided with base 36
wcout << "Long Long Int with base36 = "
<< wcstoll(string, &End, 36) << "\n";
wcout << "End String = " << End << "\n";
return 0;
}
输出:
Long Long Int with base5 = 8
End String = 56geekforgeeks
Long Long Int with base12 = 2226
End String = geekforgeeks
Long Long Int with base36 = 9223372036854775807
End String =
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。