//连接两个C_style字符串。
//收获:动态定义字符数组,可以用指针名字输出整个字符串。无需像傻子似的用for循环
//一个一个输出,而且还犯严重错误。
//感想:指针真是个难以驾驭的东西!Someday I will make it my server.
#include<iostream>
using namespace std;
int main()
{
const char *cp1="I am a hardwork ";
cout<<"cp1 is:"<<cp1<<endl;
const char *cp2="student.";
cout<<"cp2 is:"<<cp2<<endl;
size_t len=strlen(cp1)+strlen(cp2);
char *result_str=new char[len+1];
strcpy(result_str,cp1);
strcat(result_str,cp2);
cout<<"The result is:"<<result_str<<endl;
delete[] result_str;
return 0;
}
//收获:动态定义字符数组,可以用指针名字输出整个字符串。无需像傻子似的用for循环
//一个一个输出,而且还犯严重错误。
//感想:指针真是个难以驾驭的东西!Someday I will make it my server.
#include<iostream>
using namespace std;
int main()
{
const char *cp1="I am a hardwork ";
cout<<"cp1 is:"<<cp1<<endl;
const char *cp2="student.";
cout<<"cp2 is:"<<cp2<<endl;
size_t len=strlen(cp1)+strlen(cp2);
char *result_str=new char[len+1];
strcpy(result_str,cp1);
strcat(result_str,cp2);
cout<<"The result is:"<<result_str<<endl;
delete[] result_str;
return 0;
}