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

C++入门经典-例6.20-修改string字符串的单个字符

时间:2017-09-18 10:53:13      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:pen   src   输入   alt   字符串连接   lap   opened   isp   end   

1:使用+可以将两个string 字符串连接起来。同时,string还支持标准输入输出函数。代码如下:

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

#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string str1 = "您好,";
    string str2;
    cout<<"请输入您的姓名:"<<endl;
    cin>>str2;
    str1 = str1+str2;
    string str3 = "!明日科技为您服务。";
    str1 += str3;
    cout<<str1<<endl;
    return 0;
}
View Code

运行结果:

技术分享

C++入门经典-例6.20-修改string字符串的单个字符

标签:pen   src   输入   alt   字符串连接   lap   opened   isp   end   

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

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