孤独的猫

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

类属算法replace的作用是把一个区间中所有等于某个特定值的元素用另一个值代替

1 #include <iostream>
2 #include <cassert>
3 #include <algorithm>
4 #include <vector>
5 #include <string>
6  using namespace std;
7
8  int main()
9 {
10 cout<<"Illustrating the generic replace algorithm."<<endl;
11 string s("FERRARI");
12 vector<char> vector1(s.begin(),s.end());
13
14 replace(vector1.begin(),vector1.end(),'R','S');
15 assert(string(vector1.begin(),vector1.end())==string("FESSASI"));
16 cout<<" --- OK."<<endl;
17 return 0;
18 }
posted on 2011-05-26 20:50  孤独的猫  阅读(256)  评论(0编辑  收藏  举报