strcat、wcscat、_mbscat

增添字串。 更多這些函式的可用安全版本,請參閱 strcat_s、wcscat_s、_mbscat_s

重要

_mbscat_s不能用於 Windows 執行階段執行的應用程式。如需詳細資訊,請參閱 /ZW 不支援 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是否有足夠的空間,這是緩衝區滿溢的潛在因素。請考慮改用_malloca

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 的範例。

.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