O'Reilly logo

C++11 for Programmers, Second Edition by Harvey M. Deitel, Abbey Deitel, Paul J. Deitel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

16.3.4. replace, replace_if, replace_copy and replace_copy_if

Figure 16.4 demonstrates replacing values from a sequence using algorithms replace, replace_if, replace_copy and replace_copy_if.

 1   // Fig. 16.4: fig16_04.cpp 2   // Algorithms replace, replace_if, replace_copy and replace_copy_if. 3   #include <iostream> 4   #include <algorithm> 5   #include <array> 6   #include <iterator> // ostream_iterator 7   using namespace std; 8  9   bool greater9( int ); // predicate function prototype10 11   int main()12   {13      const size_t SIZE = 10;14      array< int, SIZE > init =  = { 10, 2, 10, 4, 16, 6, 14, 8, 12, 10 };15      ostream_iterator< int > output( cout, " " );16 17      array< int, SIZE >  a1( init ); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required