C++ wmemmove()

The wmemmove() function in C++ copies a specified number of wide characters from source to the destination.

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

wmemmove() prototype

wchar_t* wmemmove( wchar_t* dest, const wchar_t* src, size_t count );

The wmemmove() function takes three arguments: dest, src and count. When the wmemmove() function is called, it copies count wide characters from the memory location pointed to by src to the memory location pointed to by dest.

Copying is performed even if the src and dest pointer overlaps. This is because an intermediate buffer is created where the data are first copied to from src and then finally copied to dest.

If count is equal to zero, this function does nothing.

wmemmove() Parameters

  • dest: Pointer to the wide character array where the contents are copied to
  • src: Pointer to the wide character array from where the contents are copied.
  • count: Number of wide characters to copy from src to dest.

wmemmove() Return value

  • The wmemmove() function returns dest.

Example: How wmemmove() function works?

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

int main()
	setlocale(LC_ALL, "en_US.utf8");
	wchar_t src[] = L"\u03b1\u03b2\u03b3\u03b8\u03bb\u03c9\u03c0";
	wchar_t *dest = &src[2];// dest and src overlaps
	int count = 5;
	wmemmove(dest, src, count);
	wcout << L"After copying" << endl;
	for(int i=0; i<count; i++)
	return 0;

When you run the program, the output will be:

After copying
Did you find this article helpful?