编写一段C++程序,定义两个字符数组并用字符串字面值初始化他们;
接着再定义一个字符数组存放前两个数组连接后的结果。使用strcpy和strcat把前面两个数组的内容拷贝到第三个数组中。
#include "stdafx.h"
#include "string.h"
int _tmain(int argc, _TCHAR* argv[])
{
char buf1[] = "hello";
char buf2[] = "world";
char buf3[] = "";
strcat(buf3,buf1);
strcat(buf3,buf2);
printf("%s",buf3);
getchar();
return 0;
}
用strcat 拼接,VS2012编译,输入出拼接后字符串helloworld
第一个字符串用strcpy复制到buf3,然后再用strcat把buf2连接到buf3
strcpy和strcat,一个复制一个拼接,查查用法很容易。
strcpy strcat 注意别溢出
代码都给出来了,注意别溢出就行了