C++ wcschr()

The wcschr() function in C++ searches for the first occurrence of a wide character in a wide string.

The wcschr() function is defined in <cwchar> header file.

wcschr() prototype

const wchar_t* wcschr( const wchar_t* str, wchar_t ch );
wchar_t* wcschr( wchar_t* str, wchar_t ch );

The wcschr() function takes two arguments: str and ch. It searches for the wide character ch in the wide string pointed to by str.

wcschr() Parameters

  • str: Pointer to the null terminated wide string to be searched for.
  • ch: Wide character to search for.

wcschr() Return value

If the wide character ch is found, the wcschr() function returns a pointer to the location of ch in str, otherwise returns null pointer.

Example: How wcschr() function works?

#include <cwchar>
#include <clocale>
#include <iostream>
using namespace std;

int main()
	setlocale(LC_ALL, "en_US.utf8");
	wchar_t str[] = L"\u222b\u222e\u2231\u2211\u220f";
	wchar_t ch = L'∫';// Integral sign
	if (wcschr(str, ch))
		wcout << ch << L" is present \"" << str << L"\"";
		wcout << ch << L" is not present \"" << str << L"\"";
	return 0;

When you run the program, the output will be:

∫ is present "∫∮∱∑∏"
Did you find this article helpful?