Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/string/wide/wmemmove"

From cppreference.com
< cpp‎ | string‎ | wide
m (Text replace - "cstring" to "cwchar")
m ({{c}}, ., headers sorted, fmt, langlinks)
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{cpp/title|wmemmove}}
 
{{cpp/title|wmemmove}}
{{cpp/string/wide/sidebar}}
+
{{cpp/string/wide/navbar}}
{{ddcl | header=cwchar |
+
{{ddcl|header=cwchar|
 
wchar_t* wmemmove( wchar_t* dest, const wchar_t* src, std::size_t count );
 
wchar_t* wmemmove( wchar_t* dest, const wchar_t* src, std::size_t count );
 
}}
 
}}
  
Copies {{tt|count}} wide characters from the object pointed to by {{tt|src}} to the object pointed to by {{tt|dest}}. The objects may overlap: copying takes place as if the characters were copied to a temporary character array and then the characters were copied from the array to {{tt|dest}}. If the objects are not trivially-copyable (scalars, arrays, C-style structs), the behavior is undefined.
+
Copies exactly {{c|count}} successive wide characters from the wide character array pointed to by {{c|src}} to the wide character array pointed to by {{c|dest}}.
 +
 
 +
If {{c|count}} is zero, the function does nothing.
 +
 
 +
The arrays may overlap: copying takes place as if the wide characters were copied to a temporary wide character array and then copied from the temporary array to {{c|dest}}.
  
 
===Parameters===
 
===Parameters===
{{param list begin}}
+
{{par begin}}
{{param list item | dest | pointer to the memory location to copy to}}
+
{{par|dest|pointer to the wide character array to copy to}}
{{param list item | src | pointer to the memory location to copy from}}
+
{{par|src|pointer to the wide character array to copy from}}
{{param list item | count | number of bytes to copy}}
+
{{par|count|number of wide characters to copy}}
{{param list end}}
+
{{par end}}
  
 
===Return value===
 
===Return value===
 +
Returns a copy of {{c|dest}}.
  
{{tt|dest}}
+
===Notes===
 +
This function is not locale-sensitive and pays no attention to the values of the {{c|wchar_t}} objects it copies: nulls as well as invalid characters are copied too.
  
 
===Example===
 
===Example===
{{example cpp
+
{{example
|
+
|code=
| code=
+
#include <clocale>
| output=
+
#include <cwchar>
 +
#include <iostream>
 +
#include <locale>
 +
 
 +
int main()
 +
{
 +
    std::setlocale(LC_ALL, "en_US.utf8");
 +
    std::wcout.imbue(std::locale("en_US.utf8"));
 +
 
 +
    wchar_t str[] = L"αβγδεζηθικλμνξοπρστυφχψω";
 +
    std::wcout << str << '\n';
 +
    std::wmemmove(str + 4, str + 3, 3); // copy from [δεζ] to [εζη]
 +
    std::wcout << str << '\n';
 +
}
 +
|p=true
 +
|output=
 +
αβγδεζηθικλμνξοπρστυφχψω
 +
αβγδδεζθικλμνξοπρστυφχψω
 
}}
 
}}
  
 
===See also===
 
===See also===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list template | cpp/string/wide/dcl list wmemcpy}}
+
{{dsc inc|cpp/string/wide/dsc wmemcpy}}
{{dcl list template | cpp/algorithm/dcl list copy}}
+
{{dsc inc|cpp/string/byte/dsc memmove}}
{{dcl list template | cpp/algorithm/dcl list copy_backward}}
+
{{dsc inc|cpp/algorithm/dsc copy}}
{{dcl list template | cpp/types/dcl list is_trivially_copyable}}
+
{{dsc inc|cpp/algorithm/dsc copy_backward}}
{{dcl list end}}
+
{{dsc see c|c/string/wide/wmemmove}}
 +
{{dsc end}}
 +
 
 +
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}

Latest revision as of 11:20, 10 June 2023

Defined in header <cwchar>
wchar_t* wmemmove( wchar_t* dest, const wchar_t* src, std::size_t count );

Copies exactly count successive wide characters from the wide character array pointed to by src to the wide character array pointed to by dest.

If count is zero, the function does nothing.

The arrays may overlap: copying takes place as if the wide characters were copied to a temporary wide character array and then copied from the temporary array to dest.

Contents

[edit] Parameters

dest - pointer to the wide character array to copy to
src - pointer to the wide character array to copy from
count - number of wide characters to copy

[edit] Return value

Returns a copy of dest.

[edit] Notes

This function is not locale-sensitive and pays no attention to the values of the wchar_t objects it copies: nulls as well as invalid characters are copied too.

[edit] Example

#include <clocale>
#include <cwchar>
#include <iostream>
#include <locale>
 
int main()
{
    std::setlocale(LC_ALL, "en_US.utf8");
    std::wcout.imbue(std::locale("en_US.utf8"));
 
    wchar_t str[] = L"αβγδεζηθικλμνξοπρστυφχψω";
    std::wcout << str << '\n';
    std::wmemmove(str + 4, str + 3, 3); // copy from [δεζ] to [εζη]
    std::wcout << str << '\n';
}

Possible output:

αβγδεζηθικλμνξοπρστυφχψω
αβγδδεζθικλμνξοπρστυφχψω

[edit] See also

copies a certain amount of wide characters between two non-overlapping arrays
(function) [edit]
moves one buffer to another
(function) [edit]
copies a range of elements to a new location
(function template) [edit]
copies a range of elements in backwards order
(function template) [edit]
C documentation for wmemmove