不用string实现字符串连接

#include<iostream>
#include<cstdio>
#include<string.h>
#define N 100
using namespace std;
int main(void){
    char a[N];
    char b[N]; 
    char c[2*N];
    int i;
    cout<<"请输入a:"<<endl;
    cin>>a;
    cout<<"请输入b:"<<endl;
    cin>>b;
    int lenght1;
    int lenght2;
    lenght1=strlen(a);
    lenght2=strlen(b);
    for(i=0;i<lenght1;i++){
        c[i]=a[i];
    }
    for(i=lenght1;i<lenght1+lenght2;i++){
        c[i]=b[i-lenght1];
    }
    c[lenght1+lenght2]='\0';
    cout<<"连接完的字符串为:"<<c<<endl;
}

运行结果:
 字符串连接 随笔

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄