Contents  1-5  6-11  12-16  17-21  22-27   28-33  34 - 38  39-46  Projects   MFC

   Contact
   Search
   C
   C++
   Visual Basic
   Java
   JavaScript
   DHTML
   Style Sheets
   About
   Active X
   TDC Binding
   PHP
   Perl and CGI
   Flash
   XML
   SQL
   Messages
   Chat
   MCSE
   Linux
   Cabling   
   ActionScript
   Downloads
   E-Cards   
 
    
    

Mutating sequence algorithms perform operations that change elements in a sequence.   An example is fill().  Filling
the elements in a sequence with a given value changes them:

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
template<class T>
class PrintMe
{
public:
	void operator()(const T & t)
	{
		cout << t << " ";
	}
};
int main()
{
	PrintMe<int>	PrintThis;
	vector<int>	vInt(10);
	fill(vInt.begin(), vInt.begin() + 5, 1);
	fill(vInt.begin() + 5, vInt.end(), 2);
	for_each(vInt.begin(), vInt.end(), PrintThis);
	cout << "\n\n";
	return 0;
}
Output:   1 1 1 1 1 2 2 2 2 2

 


©2004 C. Germany