Share via


strcat, wcscat, _mbscat

附加字串。 這些函式有更安全的版本可供使用;請參閱 、、 _mbscat_swcscat_sstrcat_s

重要

在 Windows 執行階段中執行的應用程式中無法使用 _mbscat_s。 如需詳細資訊,請參閱 CRT functions not supported in Universal Windows Platform apps (通用 Windows 平台應用程式中不支援的 CRT 函式)。

語法

char *strcat(
   char *strDestination,
   const char *strSource
);
wchar_t *wcscat(
   wchar_t *strDestination,
   const wchar_t *strSource
);
unsigned char *_mbscat(
   unsigned char *strDestination,
   const unsigned char *strSource
);
template <size_t size>
char *strcat(
   char (&strDestination)[size],
   const char *strSource
); // C++ only
template <size_t size>
wchar_t *wcscat(
   wchar_t (&strDestination)[size],
   const wchar_t *strSource
); // C++ only
template <size_t size>
unsigned char *_mbscat(
   unsigned char (&strDestination)[size],
   const unsigned char *strSource
); // C++ only

參數

strDestination
以 Null 終止的目的地字串。

strSource
以 Null 結束的來源字串。

傳回值

所有這些函式都會傳回目的地字串 (strDestination)。 未保留表示錯誤的傳回值。

備註

strcat 函式會將 strSource 附加至 strDestination,並終止具有 Null 字元的產生字串。 strSource 的初始字元會覆寫 strDestination 的終止 Null 字元。 如果來源和目的字串重疊,則 strcat 的行為未定義。

重要

因為 strcat 在附加 strSource 之前不會檢查 strDestination 中是否有足夠的空間,所以這是緩衝區滿溢的潛在原因。 請考慮改用 strncat

wcscat_mbscat 分別是 strcat 的寬字元版本和多位元組字元版本。 的引數和傳回值 wcscat 是寬字元字串。 的引數和傳回值 _mbscat 是多位元組字元字串。 除此之外,這三個函式的行為相同。

在 C++ 中,這些函式具有樣板多載,可以叫用這些函式的更新且安全的對應版本。 如需詳細資訊,請參閱 保護範本多載

泛型文字常式對應

TCHAR.H 常規 _UNICODE_MBCS 未定義 _MBCS 定義 _UNICODE 定義
_tcscat strcat _mbscat wcscat

需求

常式 必要的標頭
strcat <string.h>
wcscat <string.h><wchar.h>
_mbscat <mbstring.h>

如需相容性詳細資訊,請參閱相容性

範例

請參閱 的 strcpy 範例。

另請參閱

字串操作
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