// replace.cpp -- 2011-10-03-18.40
#include "stdafx.h"
#include <iostream>
#include <algorithm>
#include <vector>
using std ::vector ;
template<class T>
class Print
{
public:
void operator () (const T & t) const
{
std ::cout << t << " " ;
}
} ;
int _tmain(int argc, _TCHAR* argv[])
{
int arr1[] = {1, 2, 3, 4, 5 ,6, 7, 8, 9} ;
vector<int> vec1(arr1, arr1 + sizeof arr1 / sizeof (int)) ;
// replace (beg, end, old_val, new_val) ;
// 操作前:[beg,end)标示输入序列.old_val是希望被替换的值.new_val是用来代替old_val的新值.
// 操作后:输入序列中所有old_val被替换为new_val.
// 返回值:无.
// 备注: old_val、new_val必须同输入序列中的值的类型完全匹配.
replace(vec1.begin(), vec1.end(), 1, 100) ;
for_each(vec1.begin(), vec1.end(), Print<int> ()) ;
std ::cin.get() ;
return 0 ;
}
replace
最新推荐文章于 2022-11-22 09:38:35 发布