std::wmemcpy(3)
๐ NAME ๐
Okay so this is the manual page for std::wmemcpy(3) from the C++ Standard Libary (yes, that's the typo in the header, and we're leaving it ๐). The function is std::wmemcpy โ NAME literally says std::wmemcpy - std::wmemcpy, which is giving "I have one job and it's copying wide characters" energy. Periodt.
๐ธ Synopsis ๐ธ
Defined in header <cwchar>:
Defined in header <cwchar>
wchar_t* wmemcpy( wchar_t* dest, const wchar_t* src, std::size_t count );
It 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 the objects overlap, the behavior is undefined โ like, not "maybe weird", actually undefined, bestie ๐ญ. If count is zero, the function does nothing. Zero. Nada. It simply vibes.
๐ 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 ๐ข
๐ Return value ๐
dest โ that's it. That's the whole return value. Iconic, honestly.
๐ฆ Notes ๐ฆ
This function's analog for byte strings is std::strncpy, not std::strcpy โ not me stressing this difference, but here we are ๐
.
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. It's not judging, it's just copying, no cap.
โจ Example โจ
// Run this code
#include <clocale>
#include <cwchar>
#include <iostream>
#include <iterator>
#include <locale>
int main(void)
{
const wchar_t from1[] = L"เคจเคฎเคธเคค";
const wchar_t from2[] = L"ิฒีกึึ";
const std::size_t sz1 = std::size(from1);
const std::size_t sz2 = std::size(from2);
wchar_t to[sz1 + sz2];
std::wmemcpy(to, from1, sz1); // copy from1, along with its null terminator
std::wmemcpy(to + sz1, from2, sz2); // append from2, along with its null terminator
std::setlocale(LC_ALL, "en_US.utf8");
std::wcout.imbue(std::locale("en_US.utf8"));
std::wcout << L"Wide array contains: ";
for (std::size_t n = 0; n < std::size(to); ++n)
if (to[n])
std::wcout << to[n];
else
std::wcout << L"\\0";
std::wcout << L'\n';
}
๐ Possible output ๐
Wide array contains: เคจเคฎเคธเคค\0ิฒีกึึ\0
๐ See also ๐
strncpyโ copies a certain amount of characters from one string to another (function) ๐wmemmoveโ copies a certain amount of wide characters between two, possibly overlapping, arrays (function) ๐ฆ- C documentation for
wmemcpy๐
Signed with sparkles and zero overlap, bestie ๐ โ source: http://cppreference.com, version/date: 2024.06.10, manual page: std::wmemcpy(3). Mwah! ๐
๐ฆ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 ยท MIT
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms