C++ Primer 课后联系9.44
2016-12-06 19:27
381 查看
9.44
#include #include using namespace std; void oops_func(string & s1,const string & s2,const string & s3); int main(void) { string s = "Rachel Monica Joey Chandler Phobe"; string newval = "Ross"; string oldval = "Monica"; cout << s << endl; oops_func(s, oldval, newval); cout << s << endl; return 0; } void oops_func(string & s1,const string & s2,const string & s3) { for (int i = 0; i <= s1.size(); i++) { if (s1.substr(i, s2.size()) == s2) { s1.replace(i, s2.size(), s3); i += s3.size() - 1; } } }
相关文章推荐
- C++ 字符串与char*转换
- C++ primer课后练习9.43
- CMakeLists.txt使用C++11标准
- 杭电OJ1002
- 深度探索c++对象模型之template中的名称决议方式
- C++中static数据成员详解
- [C++] Running time and Integer to String
- leetcode刷题系列--206. Reverse Linked List 递归和非递归 c++实现
- C++ This 详解
- C++ - 正则表达式(regex) 替换(replace) 的 详解 及 代码
- C++ 多线程调用Python脚本
- c++中的set_new_handler和new_handler
- 神思二代身份证读卡器Demo的C++版本
- vc++6.0单步执行
- 经典递归解决汉诺塔!
- C++ 函数调用 默认参数
- C++虚继承和虚基类
- 大小端
- androidNDK开发中c与C++的细小区别
- C语言 栈的表示和实现详细介绍