📅  最后修改于: 2023-12-03 15:13:57.177000             🧑  作者: Mango
strcat()
是C++中的一个函数,用于将一个字符串追加到另一个字符串的末尾。
char* strcat(char* destination, const char* source);
strcat()
的返回值为目标字符串(destination)的地址。
strcat()
函数的作用是将一个字符串追加到另一个字符串的末尾。它将源字符串中的字符复制到目标字符串中,并添加一个空字符('\0'),以标记目标字符串的结尾。
#include <iostream>
#include <cstring> // C++中字符串操作库
int main() {
char str1[50] = "Hello";
char str2[50] = "World";
strcat(str1, str2);
std::cout << str1 << std::endl; // 输出"HelloWorld"
return 0;
}
strcat()
函数已经不再建议使用,因为它有安全性漏洞。建议使用更安全的函数strcat_s()
或者strncat_s()
代替。