📜  C / C++中的wcsspn()函数与示例

📅  最后修改于: 2021-05-25 19:58:52             🧑  作者: Mango

wcsspn()是C / C++中的内置函数,它返回由另一个宽字符串存在的字符组成的宽字符串的最大初始段的长度。它在C++的cwchar头文件中定义。

语法

wcsspn(des, src)

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

  • des :指定要搜索的以null终止的宽字符串。
  • src :指定一个以null终止的宽字符串,其中包含要搜索的字符。

返回值:该函数返回des的最大初始段的长度,该段仅包含src指向的宽字符串的宽字符。

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

程序1

// C++ program to illustrate the
// wcsspn() function
#include 
#include 
using namespace std;
  
int main()
{
    wchar_t src[] = L"161106010";
    wchar_t des[] = L"6010IshwarGupta";
    int length = wcsspn(des, src);
  
    if (length > 0)
        wcout << des << L" contains " << 
                 length << L" initial numbers";
    else
        wcout << des << L" doesn't start with numbers";
  
    return 0;
}
输出:
6010IshwarGupta contains 4 initial numbers

程序2

// C++ program to illustrate the
// wcsspn() function
#include 
#include 
using namespace std;
  
int main()
{
    wchar_t src[] = L"2018";
    wchar_t des[] = L"GeeksforGeeks";
    int length = wcsspn(des, src);
  
    if (length > 0)
        wcout << des << L" contains " << 
                 length << L" initial numbers";
    else
        wcout << des << L" doesn't start with numbers";
  
    return 0;
}
输出:
GeeksforGeeks doesn't start with numbers
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”