码迷,mamicode.com
首页 > 编程语言 > 详细

C++入门经典-例6.5-连接字符串

时间:2017-09-16 16:12:46      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:com   include   color   运行   cat   class   函数   hid   .cpp   

1:运行代码如下:

技术分享
// 6.5.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream>
using std::cout;
using std::endl;
using std::cin;
void main()
{
    char str1[30],str2[20];
    cout<<"请输入数组1:"<< endl;
    cin>>str1;
    cout<<"请输入数组2"<<endl;
    cin>>str2;
    if(30>strlen(str1)+strlen(str2))//strlen用于获取字符串长度
    {
        strcat(str1,str2);//字符串连接函数
        cout <<"Now the string1 is:"<<str1<<endl;
    }
    else 
        cout<<"操作失败"<<endl;
 }
View Code

运行结果:

技术分享

C++入门经典-例6.5-连接字符串

标签:com   include   color   运行   cat   class   函数   hid   .cpp   

原文地址:http://www.cnblogs.com/lovemi93/p/7531390.html

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