⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 for_each.cpp

📁 For_each函数的用法!
💻 CPP
字号:
#include <functional>
#include <vector> 
#include <algorithm>
#include <iostream>

using namespace std;
//template <class T> 
class out_times_x 
{
private:
	int multiplier;

public:

	out_times_x(const int& k) : multiplier(k) { }

	void operator()(const int& x) { cout << x * multiplier << " " << endl; }

};


int main ()
{
	int sequence[5] = {1,2,3,4,5};  

	vector<int>  v(sequence, sequence+5);


	out_times_x f2(3);

	for_each(v.begin(),v.end(),f2);   // Apply function

	system("pause");


	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -