_strset、_strset_l、_wcsset、_wcsset_l、_mbsset、_mbsset_l_strset, _strset_l, _wcsset, _wcsset_l, _mbsset, _mbsset_l

将字符串的字符设置为一个字符。Sets characters of a string to a character. 这些函数的更安全版本已经发布;请参阅 _strset_s、_strset_s_l、_wcsset_s、_wcsset_s_l、_mbsset_s、_mbsset_s_lMore secure versions of these functions are available; see _strset_s, _strset_s_l, _wcsset_s, _wcsset_s_l, _mbsset_s, _mbsset_s_l.

重要

_mbsset_mbsset_l不能用于在 Windows 运行时中执行的应用程序。_mbsset and _mbsset_l cannot be used in applications that execute in the Windows Runtime. 有关详细信息,请参阅通用 Windows 平台应用中不支持的 CRT 函数For more information, see CRT functions not supported in Universal Windows Platform apps.

语法Syntax

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
);

参数Parameters

strstr
要设置的 null 终止字符串。Null-terminated string to be set.

cc
字符设置。Character setting.

localelocale
要使用的区域设置。Locale to use.

返回值Return Value

返回指向修改后的字符串的指针。Returns a pointer to the altered string.

备注Remarks

_Strset函数将所有字符 (不包括终止 null 字符) 的strc,转换为charThe _strset function sets all characters (except the terminating null character) of str to c, converted to char. _wcsset_mbsset_l宽字符及多字节字符版本的 _strset,和自变量和返回值的数据类型相应变化。_wcsset and _mbsset_l are wide-character and multibyte-character versions of _strset, and the data types of the arguments and return values vary accordingly. 否则这些函数具有相同行为。These functions behave identically otherwise.

_mbsset验证其参数。_mbsset validates its parameters. 如果str是 null 指针,则调用无效参数处理程序,如中所述参数验证If str is a null pointer, the invalid parameter handler is invoked, as described in Parameter Validation. 如果允许执行继续,则 _mbsset返回NULL和设置errnoEINVALIf execution is allowed to continue, _mbsset returns NULL and sets errno to EINVAL. _strset_wcsset不会验证其参数。_strset and _wcsset do not validate their parameters.

输出值受的设置LC_CTYPE的区域设置的类别设置影响; 请参阅setlocale、 _wsetlocale有关详细信息。The output value is affected by the setting of the LC_CTYPE category setting of the locale; see setlocale, _wsetlocale for more information. 这些函数的版本是相同的只不过不是具有 _l后缀使用当前区域设置的以及是否有 _l后缀改为使用的区域设置参数的在中传递。The versions of these functions are identical, except that the ones that don't have the _l suffix use the current locale and the ones that do have the _l suffix instead use the locale parameter that's passed in. 有关详细信息,请参阅 LocaleFor more information, see Locale.

重要

这些函数可能容易受到的缓冲区溢出的威胁。These functions might be vulnerable to buffer overrun threats. 缓冲区溢出可以用于系统攻击,因为它们可能使权限的提升不能确保。Buffer overruns can be used for system attacks because they can cause an unwarranted elevation of privilege. 有关详细信息,请参阅 避免缓冲区溢出For more information, see Avoiding Buffer Overruns.

一般文本例程映射Generic-Text Routine Mappings

TCHAR.H 例程TCHAR.H routine 未定义 _UNICODE 和 _MBCS_UNICODE & _MBCS not defined 已定义 _MBCS_MBCS defined 已定义 _UNICODE_UNICODE defined
_tcsset_tcsset _strset_strset _mbsset_mbsset _wcsset_wcsset
_tcsset_l_tcsset_l _strset_l_strset_l _mbsset_l_mbsset_l _wcsset_l_wcsset_l

要求Requirements

例程Routine 必需的标头Required header
_strset_strset <string.h><string.h>
_strset_l_strset_l <tchar.h><tchar.h>
_wcsset_wcsset <string.h> 或 <wchar.h><string.h> or <wchar.h>
_wcsset_l_wcsset_l <tchar.h><tchar.h>
_mbsset_mbsset_l_mbsset, _mbsset_l <mbstring.h><mbstring.h>

有关其他兼容性信息,请参阅 兼容性For additional compatibility information, see Compatibility.

示例Example

// 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 );
}
Before: Fill the string with something.
After:  *******************************

请参阅See also

字符串操作String Manipulation
区域设置Locale
多字节字符序列的解释Interpretation of Multibyte-Character Sequences
_mbsnbset、_mbsnbset_l_mbsnbset, _mbsnbset_l
memset、wmemsetmemset, wmemset
strcat、wcscat、_mbscatstrcat, wcscat, _mbscat
strcmp、wcscmp、_mbscmpstrcmp, wcscmp, _mbscmp
strcpy、wcscpy、_mbscpystrcpy, wcscpy, _mbscpy
_strnset、_strnset_l、_wcsnset、_wcsnset_l、_mbsnset、_mbsnset_l_strnset, _strnset_l, _wcsnset, _wcsnset_l, _mbsnset, _mbsnset_l