1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;
using namespace std::placeholders;
ostream& print (int a, ostream& os, char c);
// print display's a single integer.
void disp (vector<int>& vec, ostream &os=cout);
// disp uses print as a predicate to display a vector obj.
int main ()
{
vector<int> myvec {1, 2, 3, 4, 5,6, 7, 8, 9};
disp (myvec);
return 0;
}
ostream& print (int a, ostream& os, char c)
{
return os<<a<<c;
}
void disp (vector<int>& vec, ostream &os)
{
cout <<"\n\n";
for_each(vec.cbegin(), vec.cend(), bind(print,_1, os,' '));
///error on bind.what's the problem?
}
|