请高手们用C++写个把两个字符串合并的程序,不要用系统函数,谢谢!
来源:百度知道 编辑:UC知道 时间:2024/05/18 09:11:23
要求讲两个字符串合并,自己写一个函数,在主函数中调用后将两个字符串合并后输出!
不使用系统函数!最好是用一维数组的形式! 真不好意思,忘了说了!
不使用系统函数!最好是用一维数组的形式! 真不好意思,忘了说了!
这个可以吧运行了的
#include <iostream.h>
# define N 50
void add(char a[],char b[],int n,int m);
void main()
{
char a[N],b[N];
int n,m;
cout<<"input shu zu chang du n ,m he 2 arrya,b"<<endl;
cin>>n>>m;
add( a, b, n, m);
}
void add(char a[],char b[],int n,int m)
{
for(int i=0;i<n;i++)
cin>>a[i];
for( i=0;i<m;i++)
cin>>b[i];
for( i=0;i<m;i++)
a[n+i]=b[i];
cout<<"output end"<<endl;
for( i=0;i<m+n;i++)
cout<<a[i];}
运行界面
input shu zu chang du n ,m he 2 arrya,b
4 5
1 2 3 4
1 2 3 4 5
output end
123412345Press any key to continue
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
string merge(string str1,string str2e)
{
return (str1+str2e);
}
int main()<