C++ Primer Fifth Edition 英文彩色带书签 http://download.csdn.net/detail/kingeasternsun/5529053
C++ Primer Plus (6th Edition) 英文原版 彩色带书签http://download.csdn.net/detail/kingeasternsun/5508691
构造 string 对象的其他方法
string s(cp, n) |
Create s as a copy of n characters from array pointed to bycp. 创建一个 string 对象,它被初始化为 cp 所指向数组的前 n 个元素的副本 |
string s(s2, pos2) |
Create s as a copy of characters in the string s2 starting at indexpos2. Undefined if 创建一个 string 对象,它被初始化为一个已存在的 string 对象 s2 中从下标 pos2 开始的字符的副本 |
string s(s2, pos2, len2) |
|
Create s as a copy of len2 characters from 创建一个 string 对象,它被初始化为 s2 中从下标 pos2 开始的 len2 个字符的副本。如果 pos2 > s2.size(),则该操作未定义,无论 len2 的值是多少,最多只能复制 s2.size() - pos2 个字符 |
|
Note: n, len2 注意:n、len2 和 pos2 都是 unsigned 值 |
string 类型特有的版本
s.insert(pos, n, c) |
Insert n copies of character c before element at indexpos. 在下标为 pos 的元素之前插入 n 个字符 c |
s.insert(pos, s2) |
Insert copy of string s2 before pos. 在下标为 pos 的元素之前插入 string 对象 s2 的副本 |
s.insert(pos, s2, pos2, len) |
|
Insert len characters from s2 starting at 在下标为 pos 的元素之前插入 s2 中从下标 pos2 开始的 len 个字符 |
|
s.insert(pos, cp, len) |
Insert len characters from array pointed to by cp beforepos. 在下标为 pos 打元素之前插入 cp 所指向数组的前 len 个字符 |
s.insert(pos, cp) |
Insert copy of null-terminated string pointed to by cp beforepos. 在下标为 pos 的元素之前插入 cp 所指向的以空字符结束的字符串副本 |
s.assign(s2) |
Replace s by a copy of s2. 用 s2 的副本替换 s |
s.assign(s2, pos2, len) |
Replace s by a copy of len characters from 用 s2 中从下标 pos2 开始的 len 个字符副本替换 s |
s.assign(cp, len) |
Replace s by len characters from array pointed to bycp. 用 cp 所指向数组的前 len 个字符副本替换 s |
s.assign(cp) |
Replace s by null-terminated array pointed to by 用 cp 所指向的以空字符结束的字符串副本替换 s |
s.erase(pos, len) |
Erase len characters starting at pos. 删除从下标 pos 开始的 len 个字符 |
Unless noted otherwise, all operations return a reference tos. 除非特殊声明,上述所有操作都返回 s 的引用 |