Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      wmemset

      From cppreference.com
      <c‎ |string‎ |wide
       
       
       
      Null-terminated wide strings
       
      Defined in header<wchar.h>
      wchar_t* wmemset(wchar_t* dest,wchar_t ch,size_t count);
      (since C95)

      Copies the wide characterch into each of the firstcount wide characters of the wide character array (or integer array of compatible type) pointed to bydest.

      If overflow occurs, the behavior is undefined.

      Ifcount is zero, the function does nothing.

      Contents

      [edit]Parameters

      dest - pointer to the wide character array to fill
      ch - fill wide character
      count - number of wide characters to fill

      [edit]Return value

      Returns a copy ofdest

      [edit]Notes

      This function is not locale-sensitive and pays no attention to the values of thewchar_t objects it writes: nulls as well as invalid wide characters are written too.

      [edit]Example

      Run this code
      #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');}

      Output:

      🍌🍌🍌🍌🍌蕉蕉蕉蕉蕉

      [edit]References

      • C23 standard (ISO/IEC 9899:2024):
      • 7.29.4.6.2 The wmemset function (p: TBD)
      • C17 standard (ISO/IEC 9899:2018):
      • 7.29.4.6.2 The wmemset function (p: TBD)
      • C11 standard (ISO/IEC 9899:2011):
      • 7.29.4.6.2 The wmemset function (p: 439)
      • C99 standard (ISO/IEC 9899:1999):
      • 7.24.4.6.2 The wmemset function (p: 385)

      [edit]See also

      fills a buffer with a character
      (function)[edit]
      copies a certain amount of wide characters between two non-overlapping arrays
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/string/wide/wmemset&oldid=153732"

      [8]ページ先頭

      ©2009-2025 Movatter.jp