11-04-1.cpp
来自「more efftive 代码」· C++ 代码 · 共 22 行
CPP
22 行
#include <iostream>#include <functional>#include <algorithm>using namespace std;template <class T> struct print : public unary_function<T, void>{ print(ostream& out) : os(out), count(0) {} void operator() (T x) { os << x << ' '; ++count; } ostream& os; int count;};int main(){ int A[] = {1, 4, 2, 8, 5, 7}; const int N = sizeof(A) / sizeof(int); print<int> P = for_each(A, A + N, print<int>(cout)); cout << endl << P.count << " object printed." << endl;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?