类属算法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 }
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 }