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

std::wcsncpy

Defined in header <cwchar>

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

最多拷贝count所指向的宽字符串的字符src%28包括将空宽字符%29终止为由dest...

如果count在整个字符串之前到达。src复制后,产生的宽字符数组不会以空结尾。

如果,在从src,,,count未到达,则会将其他空宽字符写入dest直到...的总数count文字已经写好了。

如果字符串重叠,则行为未定义。

参数

dest

-

pointer to the wide character array to copy to

src

-

pointer to the wide string to copy from

count

-

maximum number of wide characters to copy

返回值

dest...

注记

在典型的用法中,count目标数组的大小。

二次

代码语言:javascript
复制
#include <iostream>
#include <cwchar>
 
int main()
{
    wchar_t src[] = L"hi";
    wchar_t dest[6] = {L'a', L'b', L'c', L'd', L'e', L'f'};
 
    std::wcsncpy(dest, src, 5); // this will copy hi and repeat \0 three times
 
    std::wcout << "The contents of dest are: ";
    for(wchar_t c : dest) {
        if(c)
            std::wcout << c << ' ';
        else
            std::wcout << "\\0" << ' ';
    }
    std::wcout << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
The contents of dest are: h i \0 \0 \0 f

二次

另见

wcscpy

copies one wide string to another (function)

wmemcpy

copies a certain amount of wide characters between two non-overlapping arrays (function)

strncpy

copies a certain amount of characters from one string to another (function)

c用于wcsncpy的文档

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

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

扫码关注腾讯云开发者

领取腾讯云代金券