String类是由头文件String支持的(注意:头文件string.h和cstring支持对C风格字符串进行操作的C库字符串函数,但不支持string)可以把string字符串理解为string类型的变量。
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
string one("hello word!");
cout << one << endl;
string two(20, '$');
cout << two << endl;
string eight = one + two;
cout << eight << endl;
eight[0] = 'A';
cout << eight << endl;
string three(one);
cout << three << endl;
string four;
cout << four << endl;
char ch[] = "ABCDEFG";
string five(ch, 5);
cout << five << endl;
string six(ch, 2, 6);
cout << six << endl;
string seven(one, 3);
cout << seven << endl;
return 0;
}