源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

c++ 连接两个字符串实现代码 实现类似strcat功能

  • 时间:2022-10-29 16:16 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:c++ 连接两个字符串实现代码 实现类似strcat功能
[u]复制代码[/u] 代码如下:
#include "stdafx.h" #include<iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { char s1[60]="kingbaby"; char *s2="hello"; int i=0;int j=0; while(s1[i]!='\0')i++; while((s1[i]=s2[j])!='\0'){ j++;i++; } cout<<s1<<endl; return 0; }
方法二
[u]复制代码[/u] 代码如下:
#include "stdafx.h" #include<iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { char a[20] ="aaaa"; char b[10]="bbb"; char *stra=a; char *strb=b; while(*stra!='\0')stra++; while(*strb!='\0') { *stra=*strb;//同时移动指针 strb++; stra++; } return 0; }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部