/*
* 介绍string类;
* 我们先来了解一下string的构造函数:
* 1)将string对象初始化为s指向的NBTS
* string(const char *s)
* 2) 创建一个包含n个元素的string对象,其中每个元素都被初始化为字符c
* string(size_type n, char c)
* 3) 将string对象初始化为对象str中从位子pos开始到结尾的字符,或从位置pos开始的n个字符
* string(const string & str, string size_type n=npos)
* 4)创建一个默认的string对象,长度为0
* string()
* 5)将string对象初始化为s指向的NBTS中的前n个字符
* string(const char * s, size_type n)
* 6)将string对象初始化为区间 [begin, end]内的字符,其中begin和end的行为就像指针,用于制定位子
* template<class Iter>
* string(Iter begin, Iter end)
*
*/
#include<iostream>
#include<string>
int main() {
using namespace std;
string one("Lottery Winner!"); //构造函数1
cout << one << endl;
string two(20, 's'); // 构造函数2:将string对象two初始化为由20个$字符组成的字符串
cout << two << endl;
string three(one); // 构造函数3:复制构造函数将string对象three初始化为string对象one
cout << three << endl;
one += "Oops!"; // 重载函数:重载的+=操作符将字符串“Oops!”附加到字符串one后面
two = "Sorry! That was";
three[0] = 'p';
string four; //构造函数4
four = two + three; // 重载函数
cout << four << endl;
char alls[] = "All's well that ends well";
string five(alls, 20); // 构造函数5
cout << five << "!\n";
string six(alls + 6, alls + 10); // 构造函数6
cout << six << ",";
string seven(&five[6], &five[10]);
cout << seven << "...\n";
return 0;
}