)
{
cout << val << " ";
}
};
void test01()
{
vector v = { 4,7,2,7,8,7,9,7,10 };
cout << "替换前...:";
for_each(v.begin(), v.end(), p());
cout << "\n替换后: ";
replace(v.begin(), v.end(), 7, 520);
for_each...孙悟空2", 19);
person p3("孙悟空3", 20);
person p4("猪八戒", 20);
vector v = { p1,p2,p3};
cout << "替换前...因为要查找与p1值相符的元素,所以涉及到了比较,如果是自定义数据类型,要重载==,返回值为bool
replace(v.begin(), v.end(), p1, p4);
cout << "\n替换后