名稱空間
變體
操作

std::wmemcpy

來自 cppreference.com
< cpp‎ | string‎ | wide
在標頭檔案 <cwchar> 中定義
wchar_t* wmemcpy( wchar_t* dest, const wchar_t* src, std::size_t count );

src 指向的寬字元陣列中複製精確 count 個連續寬字元到 dest 指向的寬字元陣列。如果物件重疊,則行為未定義。如果 count 為零,函式不執行任何操作。

目錄

[編輯] 引數

dest - 指向要複製到的寬字元陣列的指標
src - 指向要複製的寬字元陣列的指標
count - 要複製的寬字元數

[編輯] 返回值

dest

[編輯] 注意

此函式對於位元組字串的對應函式是 std::strncpy,而不是 std::strcpy

此函式不依賴於區域設定,也不關注所複製的 wchar_t 物件的值:空字元和無效字元也會被複制。

[編輯] 示例

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

可能的輸出

Wide array contains: नमस्ते\0Բարև\0

[編輯] 參閱

從一個字串複製一定數量的字元到另一個字串
(函式) [編輯]
在兩個可能重疊的陣列之間複製一定數量的寬字元
(函式) [編輯]
C 文件 for wmemcpy