string c++ 详解 erase find .
2015-09-23 19:33
399 查看
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | // string::erase #include <iostream> #include <string> using namespace std; int main () { string str ("This is an example phrase."); string::iterator it; // erase used in the same order as described above: //删除从位置10(从0开始算的,T为第一个位置0)开始的e之后的8个字符"example " str.erase (10,8); cout << str << endl; // "This is an phrase." //删除从迭代器开始str.begin()所指的为位置0, +9表示后移9个位置,即指向第十个位置的地址。然后删除该位置的字符 即删除字符n it=str.b egin()+9; str.erase (it); cout << str << endl; // "This is a phrase." //删除从第五个位置开始即i,到倒数第7个字符即空格之间的字符 str.erase (str.begin()+5, str.end()-7); cout << str << endl; // "This phrase." return 0; } |
相关文章推荐
- c++设计模式----解释器模式interpreter
- 【c++ templates读书笔记】【2】类模板
- 【c++ templates读书笔记】【2】类模板
- C++一个简单的手柄类模板
- C++学习记录之STL函数
- 如何使用Valgrind memcheck工具进行C/C++的内存泄漏检测
- OC语言混合编辑
- cmd下nmake编译c++文件提示找不到VC下面的头文件
- RichEdit的复制与粘贴
- 只恨当初没有你——C++等级选择篇(一)
- C常用函数的实现
- 用C开发一个简易的webserver
- Largest Point
- C语言中的知识点
- c++里面的namespace
- C++的学习心得
- 乘法口诀表
- C语言求10个整数中的最大值
- 面试---c和c++的区别
- codeblocks使用cppcheck检查代码