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

📅  最后修改于: 2021-05-26 02:35:35             🧑  作者: Mango

C / C++中的wcstoul()函数将宽字符串转换为无符号长整数
此函数将指针设置为指向宽字符串的最后一个有效字符之后的第一个字符(如果存在),否则,该指针将设置为null。直到主非空白字符被发现,此函数会忽略所有领先的空白字符。

句法:

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

  • 字符串:指定包含整数表示形式的字符串。
  • endString:指定endString的值由函数的最后一个有效字符后的字符串的下一个字符集。
  • base:指定base的有效值集为{0,2,3,…,35,36}。

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

  • 成功后,函数将转换后的整数返回为无符号的long int值。
  • 如果没有有效的转换,则返回零。

下面的程序说明了上述函数:
程序1:

// C++ program to illustrate
// wcstoul() function
// with base equal to 36
  
#include 
using namespace std;
  
int main()
{
    // initialize the wide string
    wchar_t string[] = L"999gfg";
  
    // set a pointer ponting
    // 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 -> 999gfg
Unsigned Long Int value will be -> 559753324
End String will be->

程式2:

// C++ program to illustrate
// wcstoul() function
// with different bases
  
#include 
using namespace std;
  
int main()
{
    // initialize the wide string
    wchar_t string[] = L"99999999999gfg";
  
    // set a pointer ponting
    // 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 << "\n";
  
    wcout << L"Long integer value --> " << value << "\n";
  
    wcout << L"End String = " << endString << "\n";
  
    // print the unsigned long integer value with
    // the end string with base 16
    value = wcstol(string, &endString, 16);
    wcout << L"String value --> " << string << "\n";
  
    wcout << L"Long integer value --> " << value << "\n";
  
    wcout << L"End String = " << endString << "\n";
  
    // print the unsigned long integer value with
    // the end string with base 12
    value = wcstol(string, &endString, 12);
    wcout << L"String value --> " << string << "\n";
  
    wcout << L"Long integer value --> " << value << "\n";
  
    wcout << L"End String = " << endString << "\n";
  
    return 0;
}
输出:
String value --> 99999999999gfg
Long integer value --> 9223372036854775807
End String = 
String value --> 99999999999gfg
Long integer value --> 10555311626649
End String = gfg
String value --> 99999999999gfg
Long integer value --> 607915939653
End String = gfg
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”