#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
char ch1[33]="what 's your name";
char ch2[]="my name is jack";
//strcpy(ch1,ch2);
//strcpy会将ch2中的所有字符,包括结束标志"/0"一起复制到ch1中去
//不能直接对char型字符串数组进行赋值操作,如:ch1=ch2;
//strcpy(ch1,"what is your name ");
strcat(ch1,ch2);//如果是字符数组,ch1的长度必须是ch1=ch1+ch2的长度
cout<<ch1<<endl;
cout<<ch2<<endl;
return 0;
}
string字符串的合并
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str1;
cout<<"str1的长度"<<str1.size()<<endl;
str1="what is your name";
cout<<"str1的长度"<<str1.size()<<endl;
string str2;
cout<<"str2的长度"<<str2.size()<<endl;
str2="my nanme is jack";
cout<<"str2 的长度"<<str2.size()<<endl;
str1=str1+str2;
cout<<"str1的长度"<<str1.size()<<endl;
cout<<str1<<endl;
return 0;
}