C/C中的wcstoul()函数++

这个 wcstoul() C/C++中的函数将宽字符串转换为 个无符号的长整形 . 此函数将指针设置为指向宽字符串最后一个有效字符后的第一个字符(如果有),否则,指针将设置为null。此函数将忽略所有前导的空白字符,直到找到主要的非空白字符。

null

语法:

无符号长wcstoul(常量wchar_t*字符串、wchar_t**endString、int base)

参数: 该函数接受三个强制性参数,如下所述:

  • 字符串: 指定包含整数表示形式的字符串。
  • 结束字符串: 指定函数将endString的值设置为字符串中最后一个有效字符之后的下一个字符。
  • 基数: 指定基为{0,2,3,…,35,36}的有效值集。

返回值: 该函数返回两个值,如下所示:

  • 成功后,函数将转换后的整数作为 无符号长整型 价值
  • 如果没有发生有效转换,则返回零。

以下程序说明了上述功能:

项目1:

C++

// C++ program to illustrate
// wcstoul() function
// with base equal to 36
#include <bits/stdc++.h>
using namespace std;
int main()
{
// initialize the wide string
wchar_t string[] = L "999gfg" ;
// set a pointer pointing
// the string at the end
wchar_t * endString;
// print the unsigned long integer value
// with the end string
// initialize the base as 36
unsigned long value = wcstoul(string, &endString, 36);
wcout << L "String value given is -> "
<< string << endl;
wcout << L "Unsigned Long Int value will be -> "
<< value << endl;
wcout << L "End String will be-> "
<< endString << endl;
return 0;
}


输出:

String value given is -> 999gfgUnsigned Long Int value will be -> 559753324End String will be->

项目2:

C++

// C++ program to illustrate
// wcstoul() function
// with different bases
#include <bits/stdc++.h>
using namespace std;
int main()
{
// initialize the wide string
wchar_t string[] = L "99999999999gfg" ;
// set a pointer pointing
// the string at the end
wchar_t * endString;
// print the unsigned long integer value with
// the end string with base 36
long value = wcstol(string, &endString, 35);
wcout << L "String value --> " << string << "" ;
wcout << L "Long integer value --> " << value << "" ;
wcout << L "End String = " << endString << "" ;
// print the unsigned long integer value with
// the end string with base 16
value = wcstol(string, &endString, 16);
wcout << L "String value --> " << string << "" ;
wcout << L "Long integer value --> " << value << "" ;
wcout << L "End String = " << endString << "" ;
// print the unsigned long integer value with
// the end string with base 12
value = wcstol(string, &endString, 12);
wcout << L "String value --> " << string << "" ;
wcout << L "Long integer value --> " << value << "" ;
wcout << L "End String = " << endString << "" ;
return 0;
}


输出:

String value --> 99999999999gfgLong integer value --> 9223372036854775807End String = String value --> 99999999999gfgLong integer value --> 10555311626649End String = gfgString value --> 99999999999gfgLong integer value --> 607915939653End String = gfg

© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享