首页 > 编程语言 > 详细

STL中的拷贝替换算法(so easy)

时间:2017-06-08 23:17:29      阅读:250      评论:0      收藏:0      [点我收藏+]
#include"vector"
using namespace std;
#include"string"
#include"algorithm"
#include<iostream>

void printV(vector<int > tem)
{

	for (vector<int>::iterator it = tem.begin(); it != tem.end(); it++)
	{
		cout << *it << " ";
	}
	cout << endl;
}
//copy  replace replace_if  swap 

bool lowThree(int & n)
{
	return (n < 3);
}

int main()
{
	vector<int > v1;
	v1.push_back(1);
	v1.push_back(2);
	v1.push_back(3);

	vector<int > v2;
	v2.push_back(1);
	v2.push_back(6);
	v2.push_back(8);

	vector <int > v3;
	v3.resize(v1.size());
	copy(v1.begin(), v1.end(), v3.begin());
	printV(v3);

	//copy  replace replace_if  swap 
	replace(v1.begin(), v1.end(),3, 8);
	printV(v1);

	replace_if(v1.begin(), v1.end(), lowThree, 8);
	printV(v1);

	swap(v1,v2);
	printV(v1);
	printV(v2);

	system("pause");

	
}

  

STL中的拷贝替换算法(so easy)

原文:http://www.cnblogs.com/xiaochige/p/6964996.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!