3、find(p, off) 在 s [off, npos) 中查找 [p, <null>)
4、find(s2, off) 在 s [off, npos) 中查找 s2
2)find() 的变种
1、rfind() 具有 find() 的输入形式,反序查找
2、find_first_of() 具有 find() 的输入形式,返回第一个匹配的索引
3、find_last_of() 具有 find() 的输入形式,返回倒数第一个匹配的索引
4、find_first_not_of() 具有 find() 的输入形式,返回第一个不匹配的索引
5、find_last_not_of() 具有 find() 的输入形式,返回倒数第一个不匹配的索引
3)replace() 替换
1、replace(off, cnt, s2) 将 s [off, off + cnt) 替换成 s2
2、replace(off, cnt, s2, off2, cnt2) 将 s [off, off + cnt) 替换成 s2 [off2, off2 + cnt2)
3、replace(off, cnt, p) 将 s [off, off + cnt) 替换成 [p, <null>)
4、replace(off, cnt, p, cnt2) 将 s [off, off + cnt) 替换成 [p, p + cnt2)
5、replace(off, cnt, n, c) 将 s [off, off + cnt) 替换成 c * n
使用迭代器的情况:
6、replace(InF, InL, s2) 将 [InF, InL) 替换成 s2
7、replace(InF, InL, p) 将 [InF, InL) 替换成 [p, <null>)
8、replace(InF, InL, p, cnt) 将 [InF, InL) 替换成 [p, p + cnt)
9、replace(InF, InL, n, c) 将 [InF, InL) 替换成 n * c
10、replace(InF, InL, InF2, InL2) 将 [InF, InL) 替换成 [InF2, InL2)
4)erase() 删除
1、erase(off, cnt) 从字符串 s 中删除 s [off, off + cnt)
2、erase(iter) 从字符串 s 中删除 *iter
3、erase(ItF, ItL) 从字符串 s 中删除 [ItF, ItL)
八、取出字符串
1)取得 C 风格字符串
c_str() 返回常量类型的 C 风格字符串指针,copy(ptr, cnt, off = 0) 则将指定大小的字符串复制到特定指针。data() 在 Visual C++ 7.1 中仅仅调用了 c_str() 实现。
2)取得子字符串
substr(off, cnt) 取得 s [off, off + cnt) 的副本。
3)复制子字符串
copy(p, off, cnt) 将 s [off, off + cnt) 复制到 p。
九、字符串的缓冲区管理
字符串具有类似 std::vector 的缓冲区管理界面。
size() 取得有效元素长度
max_size() 取得当前内存分配器能分配的有效空间
reserve() 为缓冲区预留空间
capacity() 取得缓冲区的容量
resize() 重设串的长度,可以为其指定初始化值
十、定义输入迭代器的尾端
向 istream_iterator 传递输入流对象以创建输入迭代器,输入迭代器持有输入流对象的指针,默认创建和读取流失败的情况下该指针被设置为 0。并且在实现输入迭代器间的 operator == 相等运算时,进行持有的流对象指针的相等比较,这样,默认创建的输入迭代器将被用于匹配输入流的结束。
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-34103-16.html
统一是大势所趋
您好