The replacement algorithm replaces the specified Element value with a new value. The following prototype is used to replace all the elements with the value of old_value in the [first, last) iterator with the value of new_value.
Function prototype:
template < class ForwardIterator, class T > void replace ( ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value );
Parameter description:
First, last
Specify the iterator range to be replaced [first, last)
Old_value
Element value to be replaced
New_value
New Value of the old value to be replaced
Program example:
/*************************************** * **************************** Copyright (c) jerry Jiang ** file name: replace. CPP * Author: Jerry Jiang * Create Time: 2012-4-29 22:22:18 * mail: jbiaojerry@gmail.com * blog: http://blog.csdn.net/jerryjbiao ** Description: simple program interpretation of C ++ STL algorithm series 19 * variable algorithm: replace ************************************** * ****************************/# include <iostre Am ># include <algorithm> # include <vector> using namespace STD; int main () {int myints [] = {10, 20, 30, 30, 20, 10, 10, 20}; vector <int> myvector (myints, myints + 8); // 10 20 30 20 10 10 20 Replace (myvector. begin (), myvector. end (), 20, 99); // 10 99 30 30 99 10 10 99 cout <"myvector contains:"; for (vector <int> :: iterator it = myvector. begin (); it! = Myvector. End (); ++ it) cout <"" <* it; cout <Endl; return 0 ;}
**************************************** **************************************** **************************************** *******
C ++ classic bibliography index and resource download:Http://blog.csdn.net/jerryjbiao/article/details/7358796
**************************************** **************************************** **************************************** ********