C++ wcscat()

The wcscat() function in C++ appends a copy of a wide string to the end of another wide string.

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

wcscat() prototype

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

The wcscat() function takes two arguments: dest and src. This function appends a copy of the wide character string pointed to by src the end of wide string pointed to by dest.

The null terminating wide character at the end of dest is replaced by the first character of src and the resulting character is also null terminated.

The behaviour is undefined if

  • the strings overlap.
  • the dest array is not large enough to append the contents of src.

wcscat() Parameters

  • dest: Pointer to a null terminating wide string to append to.
  • src: Pointer to a null terminating wide string that is to be appended.

wcscat() Return value

  • The wcscat() function returns dest.

Example: How wcscat() function works?

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

int main()
{
	setlocale(LC_ALL, "en_US.utf8");
	
	wchar_t dest[50] = L"\u0905 \u0906 \u0907 \u0908 ";
	wchar_t src[50] = L"\u0915 \u0916 \u0917 \u0918 ";
	
	wcscat(dest, src);
	wcout << "After appending: " << dest ;
	
	return 0;
}

When you run the program, the output will be:

After appending: अ आ इ ई क ख ग घ
Did you find this article helpful?