第十三周 项目五--字符串操作(2.2)字符串复制功能---两个数组中的字符复制在一个数组中

来源:互联网 发布:sql删除重复行 编辑:程序博客网 时间:2024/05/12 10:26

问题及代码:

/**Copyright (c) 2014,烟台大学计算机学院*All rights reserved.*文件名称:test.cpp*作者:吴胜男*完成日期:2014年11月23日*版本号:v1.0**问题描述:将str1和str2接起来存放到str3中。*输入描述:略*程序输出:一串字符。*/#include<iostream>using namespace std;int main(){    char str1[50]="I am a happy boy\'s daddy.";    char str2[50]="where there is a will,there is a way!";    char str3[100];    int i=0,j=0;    while(str1[j]!='\0')    {        str3[i]=str1[j];        i++;        j++;    }    j=0;    while(str2[j]!='\0')    {        str3[i]=str2[j];        i++;        j++;    }    str3[i]='\0';//切记!!    cout<<"整理后的字符串"<<str3<<endl;    return 0;}

运行结果:

知识点总结:字符串复制和存放,赋值为即可。

学习心得:抄之有道。

0 0
原创粉丝点击