Share via


strcat_s, wcscat_s, _mbscat_s

追加字符串。 这些是 strcat, wcscat, _mbscat 的版本与安全增强如 CRT中的安全功能所述。

重要

_mbscat_s 不能在运行时的窗口执行的应用程序。有关更多信息,请参见 CRT 函数不支持与 /ZW

errno_t strcat_s(
   char *strDestination,
   size_t numberOfElements,
   const char *strSource 
);
errno_t wcscat_s(
   wchar_t *strDestination,
   size_t numberOfElements,
   const wchar_t *strSource 
);
errno_t _mbscat_s(
   unsigned char *strDestination,
   size_t numberOfElements,
   const unsigned char *strSource 
);
template <size_t size>
errno_t strcat_s(
   char (&strDestination)[size],
   const char *strSource 
); // C++ only
template <size_t size>
errno_t wcscat_s(
   wchar_t (&strDestination)[size],
   const wchar_t *strSource 
); // C++ only
template <size_t size>
errno_t _mbscat_s(
   unsigned char (&strDestination)[size],
   const unsigned char *strSource 
); // C++ only

参数

  • strDestination
    null 终止的目标字符串缓冲区。

  • numberOfElements
    目标字符串缓冲区的大小。

  • strSource
    null 终止的源字符串缓冲区。

返回值

零,如果成功;在失败的错误代码。

错误状态

strDestination

numberOfElements

strSource

返回值

strDestination内容

NULL 或未终止

any

any

EINVAL

不修改

any

any

NULL

EINVAL

strDestination[0] 设置为 0

any

0 或太小

any

ERANGE

strDestination[0] 设置为 0

备注

strcat_s 功能追加 strSource 到 strDestination 和停止使用 null 字符的结果字符串。 strSource 的初始字符复盖 strDestination终止 null 字符。 如果源页和目标字符串重叠,strcat_s 行为不确定。

注意第二个参数是缓冲区的总大小,而不是剩余的大小:

char buf[16];
strcpy_s(buf, 16, "Start");
strcat_s(buf, 16, " End");               // Correct
strcat_s(buf, 16 – strlen(buf), " End"); // Incorrect

wcscat_s 和 _mbscat_s 是 strcat_s的宽字符和多字节字符版本。 参数和返回 wcscat_s 的值是宽字符字符串;这些 _mbscat_s 的多字节字符字符串。 这三个功能否则具有相同的行为。

如果 strDestination 是 null 指针或不 null 终止,或者,如果 strSource 是 NULL 指针,或者,如果目标字符串过小;无效参数调用处理程序,如 参数验证所述。 如果执行允许继续,这些函数返回 EINVAL 并将 errno 到 EINVAL。

在 C++ 中,使用这些功能由模板超加载简化;超加载可能推断缓冲区长度 (自动不再需要指定范围参数),并且还可以用以较新,安全重复自动替换旧,不安全的功能。 有关更多信息,请参见安全模板重载

这些函数的" debug "版本用 0xFD 首先加载缓冲区。 若要禁用此行为,请使用 _CrtSetDebugFillThreshold

一般文本例程映射

TCHAR.H 实例

未定义的_UNICODE & _MBCS

定义的_MBCS

定义的_UNICODE

_tcscat_s

strcat_s

_mbscat_s

wcscat_s

要求

实例

必需的标头

strcat_s

<string.h>

wcscat_s

<string.h> 或 <wchar.h>

_mbscat_s

<mbstring.h>

有关其他的兼容性信息,请参见中介绍的 兼容性

示例

在参见 strcpy_s, wcscpy_s, _mbscpy_s的代码示例。

.NET Framework 等效项

System::String::Concat

请参见

参考

字符串操作(crt)

strncat, _strncat_l, wcsncat, wcsncat_l, _mbsncat _mbsncat_l

strncmp, wcsncmp, _mbsncmp, _mbsncmp_l

strncpy, _strncpy_l, wcsncpy, _wcsncpy_l, _mbsncpy, _mbsncpy_l

_strnicmp, _wcsnicmp, _mbsnicmp, _strnicmp_l, _wcsnicmp_l, _mbsnicmp_l

strrchr, wcsrchr, _mbsrchr, _mbsrchr_l

strspn, wcsspn, _mbsspn, _mbsspn_l