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

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

运行结果:

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