原型 extern char *strcat(char *dest,char *src);
用法
#include
功能
把src所指字符串添加到dest结尾处(覆盖dest结尾处的'\0')并添加'\0'。
说明
src和dest所指内存区域不可以重叠且dest必须有足够的空间来容纳src的字符串。
返回指向dest的指针。
定义个char的数组,之后用itoa函数或者是用sprintf函数把数字转换成char型,这样就可以正常连接2个字符串了。
函数名: strcat
功 能: 字符串拼接函数
用 法: char *strcat(char *destin, char *source);
程序例:
#include
#include
int main(void)
{
char destination[25];
char *blank = " ", *c = "C++", *Borland = "Borland";
strcpy(destination, Borland);
strcat(destination, blank);
strcat(destination, c);
printf("%s\n", destination);
return 0;
}
铁代码。
/* strcat example */
#include
#include
int main ()
{
char str[80];
strcpy (str,"these ");
strcat (str,"strings ");
strcat (str,"are ");
strcat (str,"concatenated.");
puts (str);
return 0;
}
//string class using demo
// string assigning
#include
#include
using namespace std;
int main ()
{
string str1, str2, str3;
str1 = "Test string: "; // c-string
str2 = 'x'; // single character
str3 = str1 + str2; // string
cout << str3 << endl;
return 0;
}
没明白你这个用for循环依次获得字符串怎么回事,是原先就定义了这些字符串,还是通过连接获取?希望你把源代码附上,讲清楚问题