C++ Standard Library C++ STL Library

C++ <cwchar> - wcscat() Function



The C++ <cwchar> wcscat() function is used to append a copy of the wide character string pointed to by source to the end of wide character string pointed to by destination. The terminating null character in destination is overwritten by the first character of source, and the resulting wide string is null-terminated.

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

Syntax

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

Parameters

destination Specify pointer to the null-terminated wide string to append to.
source Specify pointer to the null-terminated wide string to copy from.

Return Value

Returns destination.

Example:

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

#include <iostream>
#include <cwchar>
using namespace std;
 
int main (){
  wchar_t str[256] = L"Hello ";
  wcscat(str, L"World!.");
  wcout<<str<<"\n";  

  wchar_t str2[256] = L" Programming is fun.";
  wcscat(str, str2);
  wcout<<str<<"\n";   
  return 0;
}

The output of the above code will be:

Hello World!.
Hello World!. Programming is fun.

❮ C++ <cwchar> Library