C++ Standard Library C++ STL Library

C++ <cwchar> - wcscpy() Function



The C++ <cwchar> wcscpy() function is used to copy the wide string pointed to by source, including the null character, to the wide character array whose first element is pointed to by destination.

The behavior is undefined if the destination is not large enough for the content of source (including the null character), or if the strings overlap.

Syntax

wchar_t* wcscpy (wchar_t* destination, const wchar_t* source);

Parameters

destination Specify pointer to the wide character array where the content is to be copied.
source Specify pointer to the null-terminated wide string to copy from.

Return Value

Returns destination.

Example:

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

#include <iostream>
#include <cwchar>
using namespace std;
 
int main (){
  wchar_t str1[256] = L"xyz";
  wchar_t str2[256];
  wchar_t str3[256] = L"Hello World!";

  //replacing the content of str1
  //and str2 with str3
  wcscpy(str1, str3);
  wcscpy(str2, str3);

  wcout<<"str1 is: "<<str1<<"\n";
  wcout<<"str2 is: "<<str2<<"\n";   
  return 0;
}

The output of the above code will be:

str1 is: Hello World!
str2 is: Hello World!

❮ C++ <cwchar> Library