#include <iostream>using namespace std;char* strconnect(char str_1[], char str_2[], int len_1, int len_2){// 初始化字符串 str_1 的int Actlen_1 = 0;// 得到字符串 str_1 的实际长度for (int i = 0; i < len_1; i++){if (str_1[i] == '\0'){Actlen_1 = i;break;}}// 将字符串2拼接到字符串1中for (int i = 0; i <= len_2; i++){if (str_2[i] == '\0'){str_1[Actlen_1 + i] = str_2[i];break;}else{str_1[Actlen_1 + i] = str_2[i];}}// 返回拼接后的字符串return str_1;}int main(){// 初始化变量char str_1[50] = "hello, my name is qianlv. ";char str_2[20] = "what is your name?";// 得到数组长度int len_1 = sizeof(str_1) / sizeof(str_1[0]);int len_2 = sizeof(str_2) / sizeof(str_2[0]);// 拼接字符串strconnect(str_1, str_2, len_1, len_2);cout << "拼接后的字符串 = " << str_1 << endl;return 0;}
1500字范文,内容丰富有趣,写作好帮手!