wcspbrk() function in C/C++


The wcspbrk() function is a built in function of C or C++. It searches for a set of wide characters present in a wide string in another wide string. This function is present into cwhar header file.

This function takes two arguments. The first argument is destination, and the second argument is the source. As destination we have to pass null terminated wide strings to be searched. As source, we have to pass null terminated wide string, that is containing the characters that will be searched.

This function returns two values. If one or more than one wide character is present, this function returns the pointer to the first wide character in destination and also in src. If there is no wide character is present in destination or source, one null pointer is returned.

Example

#include <cwchar>
#include <iostream>
using namespace std;
main () {
   wchar_t wcs[] = L"Hello World. This is C++ PROGRAM.";
   wchar_t key[] = L"aeiouAEIOU";
   wchar_t * pwc;
   wcout << L"Vowels in '"<< wcs << "': ";
   pwc = wcspbrk (wcs, key);
   while (pwc != NULL) {
      wcout << *pwc << L" ";
      pwc = wcspbrk (pwc+1,key);
   }
   wcout << L"\n";
}

Output

Vowels in 'Hello World. This is C++ PROGRAM.': e o o i i O A

Updated on: 30-Jul-2019

92 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements