📄 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 + -