Share via


_strset、_strset_l、_wcsset、_wcsset_l、_mbsset、_mbsset_l

設定字串為字元的字元。 更多這些函式的可用安全版本,請參閱 _strset_s、_strset_s_l、_wcsset_s、_wcsset_s_l、_mbsset_s、_mbsset_s_l

重要

_mbsset 與_mbsset_l不能用於Windows 執行階段中執行的應用程式。如需詳細資訊,請參閱 /ZW 不支援 CRT 函式

char *_strset(
   char *str,
   int c 
);
char *_strset_l(
   char *str,
   int c,
   locale_t locale
);
wchar_t *_wcsset(
   wchar_t *str,
   wchar_t c 
);
wchar_t *_wcsset_l(
   wchar_t *str,
   wchar_t c,
   locale_t locale
);
unsigned char *_mbsset(
   unsigned char *str,
   unsigned int c 
);
unsigned char *_mbsset_l(
   unsigned char *str,
   unsigned int c,
   _locale_t locale
);

參數

  • str
    以null結尾的字符串進行設置。

  • c
    字元設定。

  • locale
    要使用的地區設定。

傳回值

傳回變更後字串的指標。

備註

_strset 函式會將所有字元 (除了結束的 null 字元) 轉換為 c的 str ,轉換為 char。 _wcsset 和 _mbsset_l 都是 _strset寬字元和多位元組字元版本,,且引數和傳回值的資料型別對應的變更。 這三個函式其餘部分的運作相同。

_mbsset 會驗證其參數。 如果 str 如 參數驗證 中所述為 null 指標,則叫用無效參數處理常式。 如果允許繼續執行, _mbsset 會傳回 NULL 並設定 errno 為 EINVAL。 _strset 和 _wcsset 並不驗證它們的參數。

輸出值會受到地區設定的 LC_CTYPE 類別設定影響。如需詳細資訊,請參閱 setlocale、_wsetlocale。 這些功能的版本是相同的,不同之處在於不具有的那些有 _l 後置字元使用當前區域設置和那些確實有 _l後置字元,而不是使用的傳入的區域設置參數。 如需詳細資訊,請參閱地區設定

安全性注意事項安全性提示

這些函式可能容易受到緩衝區滿溢的威脅。緩衝區滿溢可能被當成系統攻擊方式,因為它們可能導致非預期的提高權限。如需詳細資訊,請參閱 Avoiding Buffer Overruns

一般文字常式對應

TCHAR.H 常式

未定義 _UNICODE & _MBCS

已定義 _MBCS

已定義 _UNICODE

_tcsset

_strset

_mbsset

_wcsset

_tcsset_l

_strset_l

_mbsset_l

_wcsset_l

需求

常式

必要的標頭

_strset

<string.h>

_strset_l

<tchar.h>

_wcsset

<string.h> 或 <wchar.h>

_wcsset_l

<tchar.h>

_mbsset, _mbsset_l

<mbstring.h>

如需其他相容性資訊,請參閱 相容性

範例

// crt_strset.c
// compile with: /W3

#include <string.h>
#include <stdio.h>

int main( void )
{
   char string[] = "Fill the string with something.";
   printf( "Before: %s\n", string );
   _strset( string, '*' ); // C4996
   // Note: _strset is deprecated; consider using _strset_s instead
   printf( "After:  %s\n", string );
}
  

.NET Framework 對等用法

不適用。若要呼叫標準 C 函式,請使用 PInvoke。如需詳細資訊,請參閱平台叫用範例

請參閱

參考

字串操作 (CRT)

地區設定

多位元組字元序列的解譯

_mbsnbset、_mbsnbset_l

memset、wmemset

strcat、wcscat、_mbscat

strcmp、wcscmp、_mbscmp

strcpy、wcscpy、_mbscpy

_strnset、_strnset_l、_wcsnset、_wcsnset_l、_mbsnset、_mbsnset_l