首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::wmemcpy

Defined in header <cwchar>

wchar_t* wmemcpy( wchar_t* dest, const wchar_t* src, std::size_t count );

精确复制count所指向的宽字符数组中的连续宽字符。src指向的宽字符数组dest如果对象重叠,则行为未定义。如果count等于零,函数什么也不做。

参数

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

返回值

dest...

注记

此函数%27s模拟字节字符串是std::strncpy,不是std::strcpy...

此函数不区分区域设置,也不注意wchar_t它复制的对象:NULL以及无效字符也被复制。

二次

代码语言:javascript
复制
#include <iostream>
#include <cwchar>
#include <clocale>
#include <locale>
 
int main(void)
{
    wchar_t from1[] = L"नमस्ते";
    const size_t sz1 = sizeof from1 / sizeof *from1;
    wchar_t from2[] = L"Բարև";
    const size_t sz2 = sizeof from2 / sizeof *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::cout.imbue(std::locale("en_US.utf8"));
    std::wcout << "Wide array contains: ";
    for(size_t n = 0; n < sizeof to / sizeof *to; ++n)
        if(to[n])
            std::wcout << to[n];
        else
            std::wcout << "\\0";
    std::wcout << '\n';
}

二次

可能的产出:

二次

代码语言:javascript
复制
Wide array contains: नमस्ते\0Բարև\0

二次

另见

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 wmemcpy文档

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券