c++ 连接两个字符串实现代码 实现类似strcat功能
c++ 连接两个字符串实现代码 实现类似strcat功能
发布时间:2016-12-28 来源:查字典编辑
摘要:复制代码代码如下:#include"stdafx.h"#includeusingnamespacestd;int_tmain(intargc...

复制代码 代码如下:

#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]!='')i++;

while((s1[i]=s2[j])!=''){

j++;i++;

}

cout<<s1<<endl;

return 0;

}

方法二

复制代码 代码如下:

#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!='')stra++;

while(*strb!='')

{

*stra=*strb;//同时移动指针

strb++;

stra++;

}

return 0;

}

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新C语言学习
热门C语言学习
编程开发子分类