在线文档教程
C++
字符串 | Strings

std::wcsncpy

STD::wcsncpy

Defined in header
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目标数组的大小。

二次

#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'; }

二次

产出:

二次

The contents of dest are: h i \0 \0 \0 f

二次

另见

wcscpycopies one wide string to another (function)
wmemcpycopies a certain amount of wide characters between two non-overlapping arrays (function)
strncpycopies a certain amount of characters from one string to another (function)

c用于wcsncpy的文档

© cppreference.com

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

http://en.cpPreference.com/w/cpp/string/Wide/wcsncpy