连接两个C_style字符串

//连接两个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;
}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值