C++ Standard Library C++ STL Library

C++ <cwchar> - wmemmove() Function



The C++ <cwchar> wmemmove() function is used to copy num wide characters of memory block pointed to by source to the memory block pointed to by destination.

This method can be used even when the two memory blocks overlap. This is because copying takes place as if an intermediate buffer is created where the data are first copied to from source and then finally copied to destination.

Syntax

wchar_t* wmemmove (wchar_t* destination, const wchar_t* source, size_t num);

Parameters

destination Specify pointer to the first block of memory where the content is to be copied.
source Specify pointer to the second block of memory to copy from.
num Specify number of wide characters to copy.
size_t is an unsigned integer type.

Return Value

Returns destination

Example:

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

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

  //displaying content of str
  wcout<<"str contains: "<<str<<"\n";

  //copying first 5 wide characters of str
  wmemmove(str + 5, str, 5);

  //displaying the result
  wcout<<"str contains: "<<str;

  return 0;
}

The output of the above code will be:

str contains: 1234567890
str contains: 1234512345

❮ C++ <cwchar> Library