注意
For historical reasons,and for compatibility with C, character string literals are not the same type as the standard library string type. The fact can cause confusion and is important to keep in mind when using a string literal or the string data type.
由于一些历史原因,为了与C语言兼容,字符串字面值(character string literals)与标准库中的字符串类型(string type)是不同的类型。当我们使用一个字符串值或者字符串数据类型时会产生困扰,必须牢记它们的区别。
1 Library string Type
#include<string>
using std::string;
1.1 Defining and Initializing strings
Table Ways to Initialize a string |
---|
string s1; |
string s2(s1) |
1.2 Reading and Writing strings
Reading an Unknow Number of strings
Using getline to Read an Entire Line
1.3 Operations on strings
The string size and empty Operations
string::size_type
The string Relational Operators
Assignment for strings
Adding Two strings
Adding Character String Literals and strings
Fetching a Character from a string
Subscripting Yields an Lvalue
Computing Subscript Values