指针合并字符串

来源:互联网 发布:手机触摸屏控制软件 编辑:程序博客网 时间:2024/06/07 09:12

写一个程序实现功能:将两个字符串合并为一个字符串并且输出,用指针实现。

#include<iostream>#include<string>using namespace std;void main(){char s1[100], s2[100];cout << "请输入两个字符串:" << endl;cin >> s1 >> s2;cout << s1 << " " << s2 << endl;char *p1, *p2;p1 = s1;p2 = s2;while (*p1)p1++;while (*p2){*p1 = *p2;p1++;p2++;}*p1 = '\0';cout << "合并后的字符串为:" << endl;cout << s1 << endl;system("pause");}


0 0
原创粉丝点击