名稱空間
變體
操作

wmemset

來自 cppreference.com
< c‎ | string‎ | wide
在標頭檔案 <wchar.h> 中定義
wchar_t* wmemset( wchar_t* dest, wchar_t ch, size_t count );
(自 C95 起)

將寬字元 ch 複製到 dest 指向的寬字元陣列(或相容型別的整型陣列)的前 count 個寬字元中。

如果發生溢位,行為未定義。

如果 count 為零,則函式不執行任何操作。

目錄

[編輯] 引數

dest - 指向要填充的寬字元陣列的指標
ch - 填充的寬字元
count - 要填充的寬字元數量

[編輯] 返回值

返回 dest 的副本

[編輯] 注意

此函式不區分割槽域設定,也不關注它寫入的 wchar_t 物件的值:空字元和無效寬字元也會被寫入。

[編輯] 示例

#include <locale.h>
#include <stdio.h>
#include <wchar.h>
 
int main(void)
{
    wchar_t ar[10] = L"1234567890"; // no trailing null in the array
    wmemset(ar, L'\U0001f34c', 5); // replaces [12345] with the 🍌 bananas
    wmemset(ar + 5, L'蕉', 5); // replaces [67890] with the 蕉 bananas
 
    setlocale(LC_ALL, "en_US.utf8");
    for (size_t n = 0; n < sizeof ar / sizeof *ar; ++n)
        putwchar(ar[n]);
    putwchar(L'\n');
}

輸出

🍌🍌🍌🍌🍌蕉蕉蕉蕉蕉

[編輯] 參考

  • C23 標準 (ISO/IEC 9899:2024)
  • 7.29.4.6.2 wmemset 函式 (p: TBD)
  • C17 標準 (ISO/IEC 9899:2018)
  • 7.29.4.6.2 wmemset 函式 (p: TBD)
  • C11 標準 (ISO/IEC 9899:2011)
  • 7.29.4.6.2 wmemset 函式 (p: 439)
  • C99 標準 (ISO/IEC 9899:1999)
  • 7.24.4.6.2 wmemset 函式 (p: 385)

[編輯] 另請參閱

用字元填充緩衝區
(函式) [編輯]
在兩個不重疊的陣列之間複製一定數量的寬字元
(函式) [編輯]
C++ 文件 用於 wmemset