wcsspn() function in C/C++ with Examples
The wcsspn() is a built-in function in C/C++ which returns the length of maximum initial segment of the wide string that consists of characters present in another wide string. It is defined within the cwchar header file of C++.
Syntax:
wcsspn(des, src)
Parameters:The function accepts two mandatory parameters as described below.
- des: specifies to a null terminated wide string to be searched.
- src: specifies to a null terminated wide string containing the characters to search for.
Return Value: The function returns the length of the maximum initial segment of des that contains only the wide characters from wide string pointed to by src.
Below programs illustrate the above function.
Program 1:
// C++ program to illustrate the // wcsspn() function #include <cwchar> #include <iostream> 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
Program 2:
// C++ program to illustrate the // wcsspn() function #include <cwchar> #include <iostream> 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
Recommended Posts:
- ios bad() function in C++ with Examples
- ios eof() function in C++ with Examples
- ios good() function in C++ with Examples
- quick_exit() function in C++ with Examples
- ios fail() function in C++ with Examples
- wcscmp() function in C++ with Examples
- btowc() function in C/C++ with Examples
- ios setstate() function in C++ with Examples
- wcscpy() function in C++ with Examples
- C fopen() function with Examples
- wcslen() function in C++ with Examples
- fill() function in C++ STL with examples
- fill_n() function in C++ STL with examples
- ios operator() function in C++11 with Examples
- conj() function in C++ with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



