C++ Standard Library C++ STL Library

C++ <cwchar> - wmemset() Function



The C++ <cwchar> wmemset() function copies the wide character wc into each of the first num wide characters of the wide character array pointed to by ptr.

The behavior is undefined if num is greater than the size of the wide character array pointed to by ptr.

Syntax

wchar_t* wmemset (wchar_t* ptr, wchar_t wc, size_t num);

Parameters

ptr Specify pointer to the wide character array to fill.
value Specify the fill wide character.
num Specify the number of wide characters to fill.
size_t is an unsigned integer type.

Return Value

Returns ptr.

Example:

The example below shows the usage of wmemset() function.

#include <iostream>
#include <cwchar>
using namespace std;
 
int main (){
  wchar_t str[50] = L"Hello World!";

  //displaying str
  wcout<<"str is: "<<str<<"\n";

  //setting first 5 wide characters of str to $ 
  wmemset(str, '$', 5);

  //displaying str
  wcout<<"str is: "<<str<<"\n";
  
  return 0;
}

The output of the above code will be:

str is: Hello World!
str is: $$$$$ World!

❮ C++ <cwchar> Library