wcsstr() function in C++ with example

The wcsstr() function is defined in cwchar.h header file. The wcsstr() function finds the first occurrence of a source in a destination string.

Syntax:

wchar_t* wcsstr(const wchar_t* dest, const wchar_t* src);

Parameter: This method accepts the following parameters:

Return Value: The return value of this method depeneds on:

Below program illustrate the above function:



Example 1: When the source is not found, null is returned

filter_none

edit
close

play_arrow

link
brightness_4
code

// c++ program to demonstrate
// example of wcsstr() function.
  
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  
    // initialize the destination string
    wchar_t dest[] = L"Geeks Are Geeks";
  
    // get the source string to be found
    wchar_t src[] = L"To";
  
    // Find the occurrence and print it
    wcout << wcsstr(dest, src);
  
    return 0;
}
chevron_right

Output:

Example 2: When the source is empty, destination string is returned

filter_none

edit
close

play_arrow

link
brightness_4
code

// c++ program to demonstrate
// example of wcsstr() function.
  
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  
    // initialize the destination string
    wchar_t dest[] = L"Geeks Are Geeks";
  
    // get the source string to be found
    wchar_t src[] = L"";
  
    // Find the occurrence and print it
    wcout << wcsstr(dest, src);
  
    return 0;
}
chevron_right

Output:
Geeks Are Geeks

Example 3: When the source is found, the destination from the source is returned.

filter_none

edit
close

play_arrow

link
brightness_4
code

// c++ program to demonstrate
// example of wcsstr() function.
  
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  
    // initialize the destination string
    wchar_t dest[] = L"Geeks Are Geeks";
  
    // get the source string to be found
    wchar_t src[] = L"Are";
  
    // Find the occurrence and print it
    wcout << wcsstr(dest, L"Are");
  
    return 0;
}
chevron_right

Output:
Are Geeks

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.





Check out this Author's contributed articles.

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.



Improved By : Vijay Sirra

Article Tags :
C++
Practice Tags :