/*****************************************************************************
 * This is an illustration of vector iterators.
 * ****************************************************************************/
#include <iostream>
#include <vector>
#include<string>
using std::cin; using std::cout;            
using std::endl; using std::vector;
using std::string;


void iter_show_vec(const vector<int> & v);
int main()
{
	vector<int> vec;
	int x;
	string garbage;
	cout<<" Please enter space-separated integers, "
		<<"then 's' to stop: ";
	while(cin>>x)
		vec.push_back(x);

	cin.clear();
	cin>>garbage;// Collect the 's'.
	cout<<"\nEnter an integer. The program will convert any\nof the "
		<<"original values that is greater than that integer to "
		<<"that value.\n";
		cin>>x;
	vector<int>::iterator it=vec.begin();//This cannot be a const iterator
					     // because we plan to use it to 
					     // modify  vec.
	while(it!=vec.end())
	{
		if(*it>x)
			*it=x;
		++it;
	}
	cout<<"\nThe result is \n";
	iter_show_vec(vec);
	return 0;
			
}
void iter_show_vec(const vector<int> & v)
{
	for(vector<int>::const_iterator iter=v.begin(); iter!=v.end();++iter)
		cout<<*iter<<" ";
	/* We need a const iterator here because we passed v by constant 
	 * reference.
	 */   
	return;
}
	
