C++入门经典-例6.19-字符串类型之修改string字符串的单个字符串
1:头文件
#include <string>
声明一个string变量,形式如下:
std::string s;
初始化string类型的变量:
std::string s1("字符串");
std::string s2="字符串";
std::string s3=(3,'A');//s3的内容为AAA
实例代码如下:
// 6.19.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
int main()
{
string s = "Good Morning!";
cout<<s<<endl;
cout<<"访问并修改第5个字符"<<endl;
s[4] = '!';
cout<<s<<endl;
return 0;
}
View Code
运行结果: