C++ string erase //适用于所有C++ 容器
来源:互联网 发布:php面向对象的封装 编辑:程序博客网 时间:2024/06/06 04:18
erase函数的原型如下:
(1)string& erase ( size_t pos = 0, size_t n = npos );
(2)iterator erase ( iterator position);
(3)iterator erase ( iterator first, iterator last);
也就是说有三种用法:
(1)erase(pos,n); 删除从pos开始的n个字符,比如erase(0,1)就是删除第一个字符
(2)erase(position);删除position处的一个字符(position是个string类型的迭代器)
(3)erase(first,last);删除从first到last之间的字符(first和last都是迭代器)
下面给你一个例子:
#include <iostream>#include <string>using namespace std;int main (){ string str ("This is an example phrase."); string::iterator it; // 第(1)种用法 str.erase (10,8); cout << str << endl; // "This is an phrase." // 第(2)种用法 it=str.begin()+9; str.erase (it); cout << str << endl; // "This is a phrase." // 第(3)种用法 str.erase (str.begin()+5, str.end()-7); cout << str << endl; // "This phrase." return 0;}
0 0
- C++ string erase //适用于所有C++ 容器
- c++string的erase方法
- C++STL:erase
- 【C++】vector容器和list容器中使用单个迭代器的erase函数学习笔记
- 一些操作适用于所有容器类
- C++primer_顺序容器之string操作
- C++:STL容器中,string操作
- 【c++】C++ list erase 错误
- C++STL库学习之向量容器vector & string容器
- string替换所有指定字符串(C++)
- string替换所有指定字符串(C++)
- string替换所有指定字符串(C++)
- string替换所有指定字符串(C++)
- string替换所有指定字符串(C++)
- string替换所有指定字符串(C++)
- string替换所有指定字符串(C++)
- string替换所有指定字符串(C++)
- string替换所有指定字符串(C++)
- 关于开发环境配置的一点小感想
- 安卓生成EAN13
- 字符串处理函数strcpy(), strcat(), strcmp()的输入输出
- IntelliJ IDEA
- CSS3制作简单动画
- C++ string erase //适用于所有C++ 容器
- 字符集过滤
- 该日在本年第几天
- 初学hibernate 查找数据—问题记录
- java 输入一个链表,反转链表后,输出链表的所有元素。
- ViewPagerIndicator(ViewPager指示器)
- json解析utils
- Python print 中的逗号小技巧
- IOS开发之深拷贝与浅拷贝(mutableCopy与Copy)详解