C++中string erase函数的使用
来源:互联网 发布:c 数据库编程 编辑:程序博客网 时间:2024/05/22 12:29
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都是迭代器)
下面给你一个例子:
// string::erase
#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;
}
你的假如是删除数组中的一项,并不能说明erase的用法。
转载出处:http://www.cnblogs.com/liyazhou/archive/2010/02/07/1665421.html
1 0
- C++中string erase函数的使用
- C++中string erase函数的使用
- C++中string erase函数的使用
- C++中string erase函数的使用
- C++中string erase函数的使用
- C++中string erase函数的使用
- C++中string erase函数的使用
- C++中string erase函数的使用
- C++中string erase函数的使用
- c++中string erase函数的使用
- C++中string erase函数的使用
- C++中string erase函数的使用(转载)
- C++中string erase函数的使用(转载)
- C++中string erase函数的使用(转载)
- C++中string erase函数的使用(转载)
- C++中string erase函数的使用(转载)
- C++中string erase函数的使用(转载)
- C++中string erase函数的使用(转载)
- kafka学习资料整理
- 深度学习框架Keras使用心得
- 作为前端你不得不知-浏览器的工作原理:网络浏览器幕后揭秘
- java实现排序(6)-快速排序
- C语言预处理
- C++中string erase函数的使用
- Thread类的interrupt(),interrupted(),isInterrupted()
- eclipse 总是崩掉,soup_session_feature_detach出错
- 解决idea中文乱码问题
- 二叉树的镜像
- filter(过滤器)与拦截器(AOP)区别
- 2.1.2 骑自行车的最短时间
- 第八届ACM山东省赛 I Parity check
- 进程与线程