码迷,mamicode.com
首页 > 其他好文 > 详细

字符串合并

时间:2015-07-15 18:30:57      阅读:80      评论:0      收藏:0      [点我收藏+]

标签:

  1. #include"stdafx.h"
  2. #include<iostream>
  3. using namespace std;
  4. void main(){
  5.  char s1[202], s2[101];
  6.  cout << "input the first string(Ended with ENTER)\n";
  7.  cin.getline(s1, 100);
  8.  cout << "input the second string(Ended with ENTER)\n";
  9.  cin.getline(s2, 100);
  10.  cout << "------------------------------------------\n";
  11.  int i=0, j=0, s1Len, s2Len, catLen;
  12.  while (s1[i])
  13.   i++;
  14.  s1Len = i;
  15.  while (s2[j])
  16.   s1[i++] = s2[j++];
  17.  s1[i] = ‘\0‘;
  18.  s2Len = j;
  19.  catLen = s1Len + s2Len;
  20.  cout << "The result cat_string is:" << endl;
  21.  cout << s1 << endl;
  22.  cout << "First string length=" << s1Len << endl;
  23.  cout << "Second string length=" << s2Len << endl;
  24.  cout << "Result cat_string length=" << catLen << endl;
  25. }

字符串合并

标签:

原文地址:http://www.cnblogs.com/jiaojienku/p/4648797.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!